:条件弃用警告rails4

时间:2017-11-30 11:32:57

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

我收到弃用警告:

DEPRECATION警告:不推荐使用Contact.belongs_to:customer声明中的以下选项:: condition。请改用示波器块。例如,以下内容:

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

应改写如下:

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

以下是:条件

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

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

1 个答案:

答案 0 :(得分:0)

这应该有效:

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