Permalink
Browse files

Fix descendants and subtree methods to work properly with scopes that…

… use joins by including the table name in the condition sql.
  • Loading branch information...
1 parent 469fe34 commit 95afdd0851d74b11fb87a1e92afcb887b4cbb0f3 Blane Dabney committed Dec 17, 2010
Showing with 3 additions and 3 deletions.
  1. +3 −3 lib/ancestry/instance_methods.rb
@@ -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 = {}
@@ -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 = {}
@@ -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.