1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

rdoc for some of the methods in JoinDependency

This commit is contained in:
Neeraj Singh 2013-04-10 14:33:39 -04:00
parent eb750e2127
commit 070dda28ae
2 changed files with 36 additions and 0 deletions

View file

@ -7,6 +7,27 @@ module ActiveRecord
attr_reader :join_parts, :reflections, :alias_tracker, :base_klass 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) def initialize(base, associations, joins)
@base_klass = base @base_klass = base
@table_joins = joins @table_joins = joins

View file

@ -123,6 +123,21 @@ module ActiveRecord
manager manager
end 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) def build_constraint(reflection, table, key, foreign_table, foreign_key)
constraint = table[key].eq(foreign_table[foreign_key]) constraint = table[key].eq(foreign_table[foreign_key])