Skip to content

Commit

Permalink
rdoc for some of the methods in JoinDependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Neeraj Singh committed Apr 10, 2013
1 parent eb750e2 commit 070dda2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
21 changes: 21 additions & 0 deletions activerecord/lib/active_record/associations/join_dependency.rb
Expand Up @@ -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
Expand Down
Expand Up @@ -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])

Expand Down

0 comments on commit 070dda2

Please sign in to comment.