diff options
author | Melanie Gilman <melanie@thoughtbot.com> | 2014-12-04 09:49:51 -0500 |
---|---|---|
committer | Melanie Gilman <melanie@thoughtbot.com> | 2014-12-04 15:06:21 -0500 |
commit | c0609dd0f0f0de604ac1ffeffdf5e3e0e7356b35 (patch) | |
tree | 8835aa2a9c924e2e76d2e04c1d92db101890535c /activerecord/lib/active_record/relation | |
parent | 2673a359e1020390cc8ae0208e7795f61c9fba89 (diff) | |
download | rails-c0609dd0f0f0de604ac1ffeffdf5e3e0e7356b35.tar.gz rails-c0609dd0f0f0de604ac1ffeffdf5e3e0e7356b35.tar.bz2 rails-c0609dd0f0f0de604ac1ffeffdf5e3e0e7356b35.zip |
Deprecate `Class` handler in `PredicateBuilder`
Users should pass strings to queries instead of classes
Diffstat (limited to 'activerecord/lib/active_record/relation')
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index eb21d01465..67e646bf18 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -35,7 +35,7 @@ module ActiveRecord # PriceEstimate.where(estimate_of: treasure) if klass && reflection = klass._reflect_on_association(column) if reflection.polymorphic? && base_class = polymorphic_base_class_from_value(value) - queries << self.class.build(table[reflection.foreign_type], base_class) + queries << self.class.build(table[reflection.foreign_type], base_class.name) end column = reflection.foreign_key @@ -84,8 +84,7 @@ module ActiveRecord end register_handler(BasicObject, ->(attribute, value) { attribute.eq(value) }) - # FIXME: I think we need to deprecate this behavior - register_handler(Class, ->(attribute, value) { attribute.eq(value.name) }) + register_handler(Class, ->(attribute, value) { deprecate_class_handler; attribute.eq(value.name) }) register_handler(Base, ->(attribute, value) { attribute.eq(value.id) }) register_handler(Range, ->(attribute, value) { attribute.between(value) }) register_handler(Relation, RelationHandler.new) @@ -100,6 +99,13 @@ module ActiveRecord end private_class_method :handler_for + def self.deprecate_class_handler + ActiveSupport::Deprecation.warn(<<-MSG.squish) + Passing a class as a value in an Active Record query is deprecated and + will be removed. Pass a string instead. + MSG + end + protected attr_reader :klass, :table |