Skip to content
Browse files

Merge pull request #10168 from neerajdotname/simple_improvements

Simple improvements
  • Loading branch information...
2 parents 9d2146a + aeafc09 commit 0b38c84332a6e19250e4c2e34ebe46cd618360b6 @rafaelfranca rafaelfranca committed Apr 10, 2013
View
25 activerecord/lib/active_record/associations/join_dependency.rb
@@ -7,6 +7,27 @@ class JoinDependency # :nodoc:
attr_reader :join_parts, :reflections, :alias_tracker, :base_klass
+ # base is the base class on which operation is taking place.
+ # associations is the list of associations which are joined using hash, symbol or array.
+ # joins is the list of all string join commnads and arel nodes.
+ #
+ # Example :
+ #
+ # class Physician < ActiveRecord::Base
+ # has_many :appointments
+ # has_many :patients, through: :appointments
+ # end
+ #
+ # If I execute `@physician.patients.to_a` then
+ # base #=> Physician
+ # associations #=> []
+ # joins #=> [#<Arel::Nodes::InnerJoin: ...]
+ #
+ # However if I execute `Physician.joins(:appointments).to_a` then
+ # base #=> Physician
+ # associations #=> [:appointments]
+ # joins #=> []
+ #
def initialize(base, associations, joins)
@base_klass = base
@table_joins = joins
@@ -58,6 +79,8 @@ def instantiate(rows)
records
end
+ protected
+
def remove_duplicate_results!(base, records, associations)
case associations
when Symbol, String
@@ -88,8 +111,6 @@ def remove_duplicate_results!(base, records, associations)
end
end
- protected
-
def cache_joined_association(association)
associations = []
parent = association.parent
View
15 activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -123,6 +123,21 @@ def join_to(manager)
manager
end
+ # Builds equality condition.
+ #
+ # Example:
+ #
+ # class Physician < ActiveRecord::Base
+ # has_many :appointments
+ # end
+ #
+ # If I execute `Physician.joins(:appointments).to_a` then
+ # reflection #=> #<ActiveRecord::Reflection::AssociationReflection @macro=:has_many ...>
+ # table #=> #<Arel::Table @name="appointments" ...>
+ # key #=> physician_id
+ # foreign_table #=> #<Arel::Table @name="physicians" ...>
+ # foreign_key #=> id
+ #
def build_constraint(reflection, table, key, foreign_table, foreign_key)
constraint = table[key].eq(foreign_table[foreign_key])
View
4 activerecord/lib/active_record/relation/query_methods.rb
@@ -934,9 +934,7 @@ def build_joins(manager, joins)
association_joins = buckets[:association_join] || []
stashed_association_joins = buckets[:stashed_join] || []
join_nodes = (buckets[:join_node] || []).uniq
- string_joins = (buckets[:string_join] || []).map { |x|
- x.strip
- }.uniq
+ string_joins = (buckets[:string_join] || []).map { |x| x.strip }.uniq
join_list = join_nodes + custom_join_ast(manager, string_joins)

0 comments on commit 0b38c84

Please sign in to comment.
Something went wrong with that request. Please try again.