diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-16 11:21:46 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-07-16 11:21:46 -0700 |
commit | e70da0e1a37ca396028f24816ea2198a06df25c0 (patch) | |
tree | 15b7ee3de3b1c39a001a9c2950a4339b91262c07 /activerecord/lib/active_record/associations | |
parent | 9eb0cd28c95aaf81db1cc2da1943fda82bb4aa8b (diff) | |
download | rails-e70da0e1a37ca396028f24816ea2198a06df25c0.tar.gz rails-e70da0e1a37ca396028f24816ea2198a06df25c0.tar.bz2 rails-e70da0e1a37ca396028f24816ea2198a06df25c0.zip |
make sure scope_chain_items has consistent types
Diffstat (limited to 'activerecord/lib/active_record/associations')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_association.rb | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index e0715d9dd1..d1bc64adf6 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -97,22 +97,24 @@ module ActiveRecord constraint = build_constraint(reflection, table, key, foreign_table, foreign_key) - scope_chain_items = scope_chain[i] + scope_chain_items = scope_chain[i].map do |item| + if item.is_a?(Relation) + item + else + ActiveRecord::Relation.new(reflection.klass, table).instance_exec(self, &item) + end + end if reflection.type - scope_chain_items += [ + scope_chain_items.concat [ ActiveRecord::Relation.new(reflection.klass, table) .where(reflection.type => foreign_klass.base_class.name) ] end - scope_chain_items += [reflection.klass.send(:build_default_scope)].compact + scope_chain_items.concat [reflection.klass.send(:build_default_scope)].compact constraint = scope_chain_items.inject(constraint) do |chain, item| - unless item.is_a?(Relation) - item = ActiveRecord::Relation.new(reflection.klass, table).instance_exec(self, &item) - end - if item.arel.constraints.empty? chain else |