diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-01-14 16:46:06 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-01-14 16:46:26 -0800 |
commit | 3204bbf8798e3203faad59bf26c3a6b3cb3de4e6 (patch) | |
tree | 1992a49db3e95b11693fa3ca91b80cb30272327b | |
parent | e64a83cdbd3ce836f3339c600c1006b20c23d8fd (diff) | |
download | rails-3204bbf8798e3203faad59bf26c3a6b3cb3de4e6.tar.gz rails-3204bbf8798e3203faad59bf26c3a6b3cb3de4e6.tar.bz2 rails-3204bbf8798e3203faad59bf26c3a6b3cb3de4e6.zip |
directly create the ARel AST
rather than allocating a new Relation, just make the AST directly
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_association.rb | 10 |
1 files changed, 4 insertions, 6 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 84e18684d8..0cd2e1a816 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -52,18 +52,16 @@ module ActiveRecord end end - if reflection.type - scope_chain_items << - ActiveRecord::Relation.create(klass, table) - .where(reflection.type => foreign_klass.base_class.name) - end - scope_chain_items.concat [klass.send(:build_default_scope)].compact rel = scope_chain_items.inject(scope_chain_items.shift) do |left, right| left.merge right end + if reflection.type + constraint = constraint.and table[reflection.type].eq foreign_klass.base_class.name + end + if rel && !rel.arel.constraints.empty? constraint = constraint.and rel.arel.constraints end |