Permalink
Browse files

Fixed ancestry to work with custom primary keys.

  • Loading branch information...
1 parent b9a102a commit 925b6a717bdcc1112c84af242e0289b0eb1eaeff @tomtaylor tomtaylor committed with stefankroes Nov 6, 2009
Showing with 7 additions and 7 deletions.
  1. +7 −7 lib/ancestry/acts_as_tree.rb
@@ -285,7 +285,7 @@ def ancestor_ids
end
def ancestor_conditions
- {:id => ancestor_ids}
+ {self.base_class.primary_key => ancestor_ids}
end
def ancestors depth_options = {}
@@ -297,7 +297,7 @@ def path_ids
end
def path_conditions
- {:id => path_ids}
+ {self.base_class.primary_key => path_ids}
end
def path depth_options = {}
@@ -352,7 +352,7 @@ def children
end
def child_ids
- children.all(:select => :id).map(&:id)
+ children.all(:select => self.base_class.primary_key).map(&self.base_class.primary_key.to_sym)
end
def has_children?
@@ -373,7 +373,7 @@ def siblings
end
def sibling_ids
- siblings.all(:select => :id).collect(&:id)
+ siblings.all(:select => self.base_class.primary_key).collect(&self.base_class.primary_key.to_sym)
end
def has_siblings?
@@ -394,20 +394,20 @@ def descendants depth_options = {}
end
def descendant_ids depth_options = {}
- descendants(depth_options).all(:select => :id).collect(&:id)
+ descendants(depth_options).all(:select => self.base_class.primary_key).collect(&self.base_class.primary_key.to_sym)
end
# Subtree
def subtree_conditions
- ["id = ? or #{self.base_class.ancestry_column} like ? or #{self.base_class.ancestry_column} = ?", self.id, "#{child_ancestry}/%", child_ancestry]
+ ["#{self.base_class.primary_key} = ? or #{self.base_class.ancestry_column} like ? or #{self.base_class.ancestry_column} = ?", self.id, "#{child_ancestry}/%", child_ancestry]
end
def subtree depth_options = {}
self.base_class.ordered_by_ancestry.scope_depth(depth_options, depth).scoped :conditions => subtree_conditions
end
def subtree_ids depth_options = {}
- subtree(depth_options).all(:select => :id).collect(&:id)
+ subtree(depth_options).all(:select => self.base_class.primary_key).collect(&self.base_class.primary_key.to_sym)
end
# Callback disabling

0 comments on commit 925b6a7

Please sign in to comment.