conditional-associations

Rails: belongs_to with conditions/scope throwing syntax error

元气小坏坏 提交于 2019-12-20 03:52:20
问题 I want to pick companies that are owned. I tried multiple combinations, new, rails 3, old school,... all of which are throwing the same syntax error unexpected '\n', expecting => belongs_to :from, class_name: 'Company', foreign_key: 'from_id', -> { where owned: true } belongs_to :from, class_name: 'Company', foreign_key: 'from_id', -> { where(owned: true) } belongs_to :from, class_name: 'Company', foreign_key: 'from_id', -> { where(:owned => true) } belongs_to :from, class_name: 'Company',

Rails: belongs_to with conditions/scope throwing syntax error

萝らか妹 提交于 2019-12-02 05:33:44
I want to pick companies that are owned. I tried multiple combinations, new, rails 3, old school,... all of which are throwing the same syntax error unexpected '\n', expecting => belongs_to :from, class_name: 'Company', foreign_key: 'from_id', -> { where owned: true } belongs_to :from, class_name: 'Company', foreign_key: 'from_id', -> { where(owned: true) } belongs_to :from, class_name: 'Company', foreign_key: 'from_id', -> { where(:owned => true) } belongs_to :from, class_name: 'Company', foreign_key: 'from_id', condition: { where(:owned => true) } Someone seems to have asked it 3 years ago