Reputation: 2714
I've got a model class:
class QRCode < ActiveRecord::Base
has_many :properties
end
So rails needs a database table named 'qr_codes' and a foreign key called 'qr_code_id'. But as a relationship in my Property Model it needs another name:
class Property < ActiveRecord::Base
belongs_to :q_r_code
end
So if I want to create a Property object I' have to say ':q_r_code => qrcode' But active_record wants a qr_code property, because the column is called 'qr_code_id'
Do I understand something wrong or is this type of name impossible to map for Rails?
P.S.: I'm using Rails 3.0.3
Upvotes: 2
Views: 2346
Reputation: 176392
belong_to accepts a :foreign_key
and :class_name
attribute.
Upvotes: 6