
Foreign key part of an integer/boolean cpk in a many-to-one relationship
Reported by Angel N. Sciortino (angelic) | July 29th, 2009 @ 12:40 PM | in 0.10.2
I have experienced errors in a many-to-one relationship when the many side has a composite key consisting of an integer and a boolean, the one side key being an integer, and the foreign key in the many side being the integer of its composite key. Example:
class ManyModel
include DataMapper::Resource
property :integer_key, Integer, :key => true
property :boolean_key, Boolean, :key => true
belongs_to :one_model, :child_key => [:integer_key]
end
class OneModel
include DataMapper::Resource
property :integer_key, Integer, :key => true
property :desc, String
has n, :many_models, :child_key => [:integer_key]
end
Attempting to access the parent from the child results in this error:
can't convert nil into Array
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/model/property.rb:187:in 'zip'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/model/property.rb:187:in 'key_conditions'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:829:in 'query'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:660:in 'collection'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/many_to_one.rb:190:in 'lazy_load'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/many_to_one.rb:96:in 'get'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/many_to_one.rb:160:in one_model'
Attempting to access the child from the parent results in this error:
can't modify frozen object
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:523:in 'original_attributes'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:92:in 'key'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:91:in 'map'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:91:in 'key'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/collection.rb:1220:in 'resource_added'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/one_to_many.rb:325:in 'resource_added'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/collection.rb:1233:in 'resources_added'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/collection.rb:1233:in 'each'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/collection.rb:1233:in 'resources_added'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/collection.rb:501:in 'concat'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/collection.rb:1022:in 'lazy_load'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/associations/one_to_many.rb:299:in 'lazy_load'
/usr/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/collection.rb:237:in 'first'
Fixed in this commit with a spec: http://github.com/angelic/dm-core/commit/f7e732f5c703108e35370d3b23...
Comments and changes to this ticket
-
Angel N. Sciortino (angelic) October 2nd, 2009 @ 10:24 AM
Created a topic branch for this and #994. http://github.com/angelic/dm-core/tree/boolean_key
-
Dan Kubb (dkubb) October 7th, 2009 @ 12:27 PM
- Milestone set to 0.10.2
- State changed from new to accepted
- Assigned user set to Dan Kubb (dkubb)
-
Dan Kubb (dkubb) October 16th, 2009 @ 01:22 AM
- State changed from accepted to resolved
(from [abe512dee51b79d1e85c6b8fa82b3ca33cbbe152]) Fix m:1 with CPK containing a boolean property
- Fix errors in a many-to-one relationship when the many side has a cpk consisting of an integer and a boolean, the one side constisting of an integer, and the fk in the many side being the integer of the cpk
[#993 state:resolved]
Signed-off-by: Dan Kubb dan.kubb@gmail.com
http://github.com/datamapper/dm-core/commit/abe512dee51b79d1e85c6b8...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Referenced by
-
994 boolean does not work as part of a composite/foreign key in one-to-one That should be #993.
-
993 Foreign key part of an integer/boolean cpk in a many-to-one relationship [#993 state:resolved]