diff --git a/lib/ancestry/instance_methods.rb b/lib/ancestry/instance_methods.rb index 6e6bbcda..99ba623e 100644 --- a/lib/ancestry/instance_methods.rb +++ b/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 \ No newline at end of file +end