我有这个关联:
has_many :foo_participators, through: :foos, source: :user, conditions: "foos.state = 'completed'"
Rails告诉我:
DEPRECATION警告:酒吧中的以下选项.has_many:foo_participators声明已弃用::conditions。请使用范围块。例如,以下内容:
has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'
应该重写如下:
has_many :spam_comments, -> { where spam: true }, class_name: 'Comment'
这可能与我的交往有关吗?
我刚问完这个问题就想明白了。出于某种原因,我没有尝试将lambda放在第一位——这样做非常有效。
has_many :foo_participators, ->{where "foos.state = 'completed'"}, through: :foos, source: :user