:conditions deprecation warning rails4

Yehor Chumak

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

This should work:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Rails4 Deprecation Warning

DEPRECATION WARNING in rails 4

Rails4 Scope or default_scope deprecation warning

Rails 5 deprecation warning for tests

deprecation warning when running rails server for associations

Rails 5.1 testing changed attributes Deprecation Warning

Deprecation warning when using Compass Rails

Rails 5.1.1 deprecation warning changed_attributes

Rails Upgrade 3.2 to 4.0: Model deprecation warning

Dangerous query method deprecation warning on Rails 5.2.3

rails Getting an DEPRECATION WARNING in my log file

Rails 5 Deprecation Warning "The behavior of `attribute_change`"

ActionController::Parameters deprecation warning: Method size is deprecated and will be removed in Rails 5.1

Deprecation warning regarding sass processor on upgrading to rails 4.2.7.1

Cannot understand rails deprecation warning for secret_token

Fix deprecation warning for an internationalization locale suffix in ruby on rails 6.1

Rails I18n validation deprecation warning

DEPRECATION WARNING after updating from Rails 5.0.0 to 5.0.0.1

Rails 4.2 DEPRECATION WARNING: `serialized_attributes` is deprecated without replacement,

upgrade sass-rails gem to 5.0 gives deprecation warning

DEPRECATION WARNING does not show for module in rails 5.2 but works with class

DEPRECATION WARNING: Method length is deprecated and will be removed in Rails 5.1

Deprecation warning from Capybara

MongoDB mongoose Deprecation Warning

Visible Deprecation warning...?

Deprecation warning from spring

Visible Deprecation Warning Python

Scalatest deprecation warning

Chartjs defaults deprecation warning