#993 ✓resolved
Angel N. Sciortino (angelic)

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

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.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »