ruby on rails - How to override default foreign key? -
i have has_many
, belongs_to
association between 2 models below:
class section < activerecord::base self.primary_key = 'id' has_many :rights end class right < activerecord::base self.primary_key = 'id' belongs_to :section end
the section table has id , section_id column well. above code associates right section via id column in section table. want associate through section_id column. how do that?
edit: on second read think misunderstood question, want relate field other primary key in section table? it's not common, hence misunderstanding.
you need use :primary_key => 'field_name'
instead of :foreign_key
belongs_to :section, :primary_key => 'section_id'
Comments
Post a Comment