Skip to content

Commit

Permalink
Fix descendants and subtree methods to work properly with scopes that…
Browse files Browse the repository at this point in the history
… use joins by including the table name in the condition sql.
  • Loading branch information
Blane Dabney committed Dec 17, 2010
1 parent 469fe34 commit 95afdd0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/ancestry/instance_methods.rb
Expand Up @@ -171,7 +171,7 @@ def is_only_child?

# Descendants
def descendant_conditions
["#{self.base_class.ancestry_column} like ? or #{self.base_class.ancestry_column} = ?", "#{child_ancestry}/%", child_ancestry]
["#{self.base_class.table_name}.#{self.base_class.ancestry_column} like ? or #{self.base_class.table_name}.#{self.base_class.ancestry_column} = ?", "#{child_ancestry}/%", child_ancestry]
end

def descendants depth_options = {}
Expand All @@ -184,7 +184,7 @@ def descendant_ids depth_options = {}

# Subtree
def subtree_conditions
["#{self.base_class.primary_key} = ? or #{self.base_class.ancestry_column} like ? or #{self.base_class.ancestry_column} = ?", self.id, "#{child_ancestry}/%", child_ancestry]
["#{self.base_class.table_name}.#{self.base_class.primary_key} = ? or #{self.base_class.table_name}.#{self.base_class.ancestry_column} like ? or #{self.base_class.table_name}.#{self.base_class.ancestry_column} = ?", self.id, "#{child_ancestry}/%", child_ancestry]
end

def subtree depth_options = {}
Expand Down Expand Up @@ -229,4 +229,4 @@ def primary_key_type
@primary_key_type ||= column_for_attribute(self.class.primary_key).type
end
end
end
end

0 comments on commit 95afdd0

Please sign in to comment.