【发布时间】:2017-07-25 04:19:35
【问题描述】:
我想选择拥有的公司。我尝试了多种组合,new、rails 3、old school……所有这些都抛出相同的语法错误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) }
3年前好像有人问过here,但是好像没有确定的答案!还有其他方法吗? Google 未返回 belongs_to with conditions 或 with scope 的相关结果
我需要准确地做this,但是那个准确的答案也会引发语法错误......
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-5 conditional-associations