aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2013-04-10 14:33:39 -0400
committerNeeraj Singh <neerajdotname@gmail.com>2013-04-10 14:33:39 -0400
commit070dda28ae1762b9c6a7e40aeeedc5bb57c15147 (patch)
treefe9b3b9a6a2a97e30bdfb36ac1835f5a723446cc /activerecord
parenteb750e2127d163be46423bcdfc08b420afa58071 (diff)
downloadrails-070dda28ae1762b9c6a7e40aeeedc5bb57c15147.tar.gz
rails-070dda28ae1762b9c6a7e40aeeedc5bb57c15147.tar.bz2
rails-070dda28ae1762b9c6a7e40aeeedc5bb57c15147.zip
rdoc for some of the methods in JoinDependency
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/associations/join_dependency.rb21
-rw-r--r--activerecord/lib/active_record/associations/join_dependency/join_association.rb15
2 files changed, 36 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency.rb b/activerecord/lib/active_record/associations/join_dependency.rb
index 93b088790e..28e081c03c 100644
--- a/activerecord/lib/active_record/associations/join_dependency.rb
+++ b/activerecord/lib/active_record/associations/join_dependency.rb
@@ -7,6 +7,27 @@ module ActiveRecord
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
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 ae1b38ff86..e4d17451dc 100644
--- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb
+++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb
@@ -123,6 +123,21 @@ module ActiveRecord
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])