加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在has_many上:通过关联,用lambda替换条件

发布时间:2020-12-17 03:23:27 所属栏目:百科 来源:网络整理
导读:我有这个协会: has_many :foo_participators,through: :foos,source: :user,conditions: "foos.state = 'completed'" Rails告诉我: DEPRECATION WARNING: The following options in your Bar.has_many :foo_participators declaration are deprecated: :co
我有这个协会:

has_many :foo_participators,through: :foos,source: :user,conditions: "foos.state = 'completed'"

Rails告诉我:

DEPRECATION WARNING: The following options in your Bar.has_many
:foo_participators declaration are deprecated: :conditions. Please use a scope
block instead. For example,the following:

06001

should be rewritten as the following:

06002

这与我的协会有可能吗?

解决方法

在我提出这个问题后立即想出来.出于某种原因,我没有尝试过将lambda放在第一位 – 这样做非常有效.

has_many :foo_participators,->{where "foos.state = 'completed'"},source: :user

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读