#belongs_to foreign key property not created immediately
Reported by massk | July 6th, 2008 @ 08:02 AM
The foreign key property is not created when calling belongs_to until the association is accessed on an instance of the class.
class Person
include DataMapper::Resource
property :id, Serial
end
class Pet
include DataMapper::Resource
property :id, Serial
belongs_to :person
end
Pet.new.person_id #=> NoMethodError
Pet.count(:person_id => 1) #=> ArgumentError: Clause :person_id does not map to a DataMapper::Property
Pet.new(:person_id => 1) #=> NameError: person_id= is not a public property
all of the above works after you call Pet#person
Pet.new.person #=> nil
Pet.new.person_id #=> nil
Pet.count(:person_id => 1) #=> 0
Pet.new(:person_id => 1) #=> #<Pet id=nil person_id=1>
this spec should have caught this, but #slice returns [nil] so the spec always passes, even though it should fail.
I have attached a patch fixing the spec above (so that it fails)
and a new spec that shows the behaviour I would have expected.
Comments and changes to this ticket
-
Dusan Maliarik August 4th, 2008 @ 02:17 PM
double this.
till now everything was perfect. I didn't updated DM, noe merb, nothing.. I didn't changed model class, controller nothing, and now I'm getting this error
-
Dirkjan Bussink September 27th, 2008 @ 07:42 AM
- → Tag changed from belongs_to bug dm-core spec to belongs_to bug "dm-core" spec
Should be fixed now, the spec doesn't fail anymore at least.
-
Dirkjan Bussink October 7th, 2008 @ 02:50 PM
- → State changed from new to resolved
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
