Skip to content

Commit

Permalink
Removed more cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwhite committed Apr 28, 2008
1 parent 108f774 commit a076437
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions lib/nested_has_many_through.rb
Expand Up @@ -14,26 +14,20 @@ def check_validity_with_nested_has_many_through!

module Association
def self.included(base)
base.send :alias_method_chain, :construct_conditions, :nested
base.send :alias_method_chain, :construct_joins, :nested
end

protected
# Build SQL conditions from attributes, qualified by table name.
def construct_conditions_with_nested
@nested_join_attributes ||= construct_nested_join_attributes
"#{@nested_join_attributes[:remote_key]} = #{@owner.quoted_id} #{@nested_join_attributes[:conditions]}"
end

def construct_joins_with_nested
@nested_join_attributes ||= construct_nested_join_attributes
@nested_join_attributes[:joins]
end
base.class_eval do
def construct_conditions
@nested_join_attributes ||= construct_nested_join_attributes
"#{@nested_join_attributes[:remote_key]} = #{@owner.quoted_id} #{@nested_join_attributes[:conditions]}"
end

def has_many_through?(reflection = @reflection)
reflection.macro == :has_many && reflection.through_reflection
def construct_joins
@nested_join_attributes ||= construct_nested_join_attributes
@nested_join_attributes[:joins]
end
end
end

protected
# Given any belongs_to or has_many (including has_many :through) association,
# return the essential components of a join corresponding to that association, namely:
#
Expand All @@ -50,7 +44,7 @@ def construct_nested_join_attributes(
association_class = reflection.klass,
table_ids = {association_class.table_name => 1})

if has_many_through?(reflection)
if reflection.macro == :has_many && reflection.through_reflection
# Construct the join components of the source association, so that we have a path from
# the eventual target table of the association up to the table named in :through, and
# all tables involved are allocated table IDs.
Expand Down

0 comments on commit a076437

Please sign in to comment.