diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-12-26 15:17:10 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-12-26 15:19:42 -0700 |
commit | a60770d3bf3a8aeac16c110f3a7d05a6d52a86d6 (patch) | |
tree | 159a11b0566e67ce8730fbbcb17052f449434f15 /activerecord/lib/active_record/relation/predicate_builder | |
parent | 35362817b16e97c9db07c5d2586a95009e747b28 (diff) | |
download | rails-a60770d3bf3a8aeac16c110f3a7d05a6d52a86d6.tar.gz rails-a60770d3bf3a8aeac16c110f3a7d05a6d52a86d6.tar.bz2 rails-a60770d3bf3a8aeac16c110f3a7d05a6d52a86d6.zip |
Remove `klass` and `arel_table` as a dependency of `PredicateBuilder`
This class cares far too much about the internals of other parts of
Active Record. This is an attempt to break out a meaningful object which
represents the needs of the predicate builder. I'm not fully satisfied
with the name, but the general concept is an object which represents a
table, the associations to/from that table, and the types associated
with it. Many of these exist at the `ActiveRecord::Base` class level,
not as properties of the table itself, hence the need for another
object. Currently it provides these by holding a reference to the class,
but that will likely change in the future. This allows the predicate
builder to remain wholy concerned with building predicates.
/cc @mrgilman
Diffstat (limited to 'activerecord/lib/active_record/relation/predicate_builder')
-rw-r--r-- | activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb b/activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb index bda2c02a10..aabcf20c1d 100644 --- a/activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb +++ b/activerecord/lib/active_record/relation/predicate_builder/association_query_handler.rb @@ -8,11 +8,12 @@ module ActiveRecord def call(attribute, value) queries = {} + table = value.associated_table if value.base_class - queries[value.association.foreign_type] = value.base_class.name + queries[table.association_foreign_type] = value.base_class.name end - queries[value.association.foreign_key] = value.ids + queries[table.association_foreign_key] = value.ids predicate_builder.build_from_hash(queries) end @@ -22,10 +23,10 @@ module ActiveRecord end class AssociationQueryValue # :nodoc: - attr_reader :association, :value + attr_reader :associated_table, :value - def initialize(association, value) - @association = association + def initialize(associated_table, value) + @associated_table = associated_table @value = value end @@ -34,7 +35,7 @@ module ActiveRecord end def base_class - if association.polymorphic? + if associated_table.polymorphic_association? @base_class ||= polymorphic_base_class_from_value end end |