简体   繁体   中英

:conditions deprecation warning rails4

i am receiving deprecation warning:

DEPRECATION WARNING: The following options in your Contact.belongs_to :customer declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:

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

should be rewritten as the following:

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

Here is the line with :condition

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

I just try some variants, but can't fix. Maybe i am missing something

This should work:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM