The primary key of Uploads is id, and there is a column named number.
When I try :
upload = Upload.find(1)
upload.uploadedfile
Rails do :
SELECT * FROM uploadedfiles WHERE (uploadedfiles.id = 255)
(255 is the value in file_number_id of course)
But I want Rails to do :
SELECT * FROM uploadedfiles WHERE (uploadedfiles.number = 255)
My question :
In belongs_to, Rails have got a parameter to name the foreign_key in the
current model, but why Rails does not have a parameter to name the
column in the other?
In some case, the column I want to search is not the primary key!
For example I could write :
belongs_to :uploadedfile, :foreign_key => “file_number_id”, :column =>
“number”
and it would send :
SELECT * FROM uploadedfiles WHERE (uploadedfiles.number = 255)