【问题标题】::conditions deprecation warning rails4:条件弃用警告 rails4
【发布时间】:2018-05-14 07:47:00
【问题描述】:

我收到了弃用警告:

弃用警告:Contact.belongs_to :customer 声明中的以下选项已弃用::conditions。请改用范围块。例如:

has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

应该改写如下:

has_many :spam_comments, -> { where spam: true }, class_name: 'Comment'

这是带有 :condition 的行

belongs_to :customer, foreign_key: 'contactable_id',\
                      conditions: "contacts.contactable_type = 'Customer'"

我只是尝试了一些变体,但无法修复。也许我错过了什么

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 deprecation-warning


    【解决方案1】:

    这应该可行:

    belongs_to :customer, -> { where(contactable_type: 'Customer') },
               foreign_key: 'contactable_id'
    

    【讨论】:

    • 谢谢,这个正在工作。看起来我在花括号内缺少括号。谢谢
    猜你喜欢
    • 2014-04-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-11
    • 2021-07-12
    • 2017-08-22
    相关资源
    最近更新 更多