Home :conditions deprecation warning rails4
Reply: 1

:conditions deprecation warning rails4

Yehor Chumak
Yehor Chumak Published in 2017-11-30 11:32:57Z

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

Marek Lipka
Marek Lipka Reply to 2017-11-30 11:34:59Z

This should work:

belongs_to :customer, -> { where(contactable_type: 'Customer') },
           foreign_key: 'contactable_id'
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.302793 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO