
#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 dm-core, belongs_to, bug, 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 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
Attachments
Tags
Referenced by
-
577 Model.all(:links => [:foo, :bar]), the first time it's run, does not initialize the foo and bar associations This may be related or identical to ticket #444: http://w...
-
577 Model.all(:links => [:foo, :bar]), the first time it's run, does not initialize the foo and bar associations This may be related or identical to ticket #444: http://w...
-
577 Model.all(:links => [:foo, :bar]), the first time it's run, does not initialize the foo and bar associations Could you please test whether this is fixed now? I think ...
-
566 loading associated objects fails Could you please test whether this is fixed now? I think ...