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 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".
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 »
