diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-01-14 16:46:57 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-01-14 16:46:57 -0800 |
commit | 2fff094c9ad27e1027cdf66eda627ded3fb67c62 (patch) | |
tree | 9b79901053cbd09c332b8b10f8e456741fb2908e /activerecord/lib/active_record | |
parent | 58e5ba0a5f87f70e0a4d4aa7eb26bc643db55e0c (diff) | |
parent | 3204bbf8798e3203faad59bf26c3a6b3cb3de4e6 (diff) | |
download | rails-2fff094c9ad27e1027cdf66eda627ded3fb67c62.tar.gz rails-2fff094c9ad27e1027cdf66eda627ded3fb67c62.tar.bz2 rails-2fff094c9ad27e1027cdf66eda627ded3fb67c62.zip |
Merge branch 'master' into set_binds
* master:
directly create the ARel AST
Updated comment to mention the enum mapping class method [ci skip]
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_association.rb | 10 | ||||
-rw-r--r-- | activerecord/lib/active_record/enum.rb | 5 |
2 files changed, 7 insertions, 8 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 09dbb96736..0dddf04fba 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -55,18 +55,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? bind_values.concat rel.bind_values constraint = constraint.and rel.arel.constraints diff --git a/activerecord/lib/active_record/enum.rb b/activerecord/lib/active_record/enum.rb index c34fc086e2..3deb2d65f8 100644 --- a/activerecord/lib/active_record/enum.rb +++ b/activerecord/lib/active_record/enum.rb @@ -54,11 +54,12 @@ module ActiveRecord # remove unused values, the explicit +Hash+ syntax should be used. # # In rare circumstances you might need to access the mapping directly. - # The mappings are exposed through a constant with the attributes name: + # The mappings are exposed through a class method with the pluralized attribute + # name: # # Conversation.statuses # => { "active" => 0, "archived" => 1 } # - # Use that constant when you need to know the ordinal value of an enum: + # Use that class method when you need to know the ordinal value of an enum: # # Conversation.where("status <> ?", Conversation.statuses[:archived]) module Enum |