
belongs_to uses class name for default FK
Reported by Michael Klishin (antares) | May 22nd, 2008 @ 05:26 PM
Say I have the following in my DM 0.9 model:
belongs_to :provider, :class_name => "Company"
Unless I specify child_key, DM looks for company_id. ActiveRecord people once decided it would be simpler to swap association implementation if association name is used for default foreign key.
It is pretty important for polymorphic associations as well: implementation with association name based FK and Discriminator would require it to make things reasonable and simple to implement.
Comments and changes to this ticket
-
-
Sam Smoot June 2nd, 2008 @ 05:21 PM
This broke a whole lot of stuff. :-/ Will work on it more tomorrow.
-
Dan Kubb (dkubb) June 2nd, 2008 @ 07:43 PM
I would like to work towards using the relationship name for the foreign key prefix in belongs_to() associations. In the example above, assuming the key for Company is a single property named "id" I would expect the foreign key to be "provider_id".
-
Jonathan Stott (namelessjon) November 30th, 2008 @ 09:06 AM
- Assigned user cleared.
- Tag set to associations, belongs_to, dm-core
- State changed from new to open
-
Dan Kubb (dkubb) January 8th, 2009 @ 04:38 AM
- State changed from open to accepted
- Assigned user set to Dan Kubb (dkubb)
-
Dan Kubb (dkubb) February 21st, 2009 @ 03:22 AM
- State changed from accepted to resolved
This is an old ticket, but I can confirm that the behavior in dm-core 0.10.0 will be to infer the foreign key using the association name rather than the model name.
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 »