Permalink
Browse files

- Version 1.1.1 (2009-10-28)

  - Fixed some parentheses warnings that where reported
  - Fixed a reported issue with arrangement
  - Fixed issues with ancestors and path order on postgres
  - Added ordered_by_ancestry scope (needed to fix issues)
  • Loading branch information...
stefankroes committed Oct 28, 2009
1 parent 1cc11a6 commit 48441fb48910fddb7b1a20882f3419cfc7124e9c
Showing with 19 additions and 14 deletions.
  1. +5 −0 README.rdoc
  2. +1 −1 ancestry.gemspec
  3. +9 −8 lib/ancestry/acts_as_tree.rb
  4. +4 −5 test/database.yml
View
@@ -214,6 +214,11 @@ The materialised path pattern requires Ancestry to use a 'like' condition in ord
The latest and recommended version of ancestry is 1.1.0. The three numbers of each version numbers are respectively the major, minor and patch versions. We started with major version 1 because it looks so much better and ancestry was already quite mature and complete when it was published. The major version is only bumped when backwards compatibility is broken. The minor version is bumped when new features are added. The patch version is bumped when bugs are fixed.
+- Version 1.1.1 (2009-10-28)
+ - Fixed some parentheses warnings that where reported
+ - Fixed a reported issue with arrangement
+ - Fixed issues with ancestors and path order on postgres
+ - Added ordered_by_ancestry scope (needed to fix issues)
- Version 1.1.0 (2009-10-22)
- Depth caching (and cache rebuilding)
- Depth method for nodes
View
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
s.description = 'Organise ActiveRecord model into a tree structure'
s.summary = 'Ancestry allows the records of a ActiveRecord model to be organised in a tree structure, using a single, intuitively formatted database column. It exposes all the standard tree structure relations (ancestors, parent, root, children, siblings, descendants) and all of them can be fetched in a single sql query. Additional features are named_scopes, integrity checking, integrity restoration, arrangement of (sub)tree into hashes and different strategies for dealing with orphaned records.'
- s.version = '1.1.0'
+ s.version = '1.1.1'
s.date = '2009-10-22'
s.author = 'Stefan Kroes'
@@ -76,6 +76,7 @@ def acts_as_tree options = {}
named_scope :children_of, lambda { |object| {:conditions => to_node(object).child_conditions} }
named_scope :descendants_of, lambda { |object| {:conditions => to_node(object).descendant_conditions} }
named_scope :siblings_of, lambda { |object| {:conditions => to_node(object).sibling_conditions} }
+ named_scope :ordered_by_ancestry, :order => "#{ancestry_column} is not null, #{ancestry_column}"
# Update descendants with new ancestry before save
before_save :update_descendants_with_new_ancestry
@@ -116,7 +117,7 @@ def orphan_strategy= orphan_strategy
# Arrangement
def arrange
# Get all nodes ordered by ancestry and start sorting them into an empty hash
- all(:order => ancestry_column).inject({}) do |arranged_nodes, node|
+ ordered_by_ancestry.all.inject({}) do |arranged_nodes, node|
# Find the insertion point for that node by going through its ancestors
node.ancestor_ids.inject(arranged_nodes) do |insertion_point, ancestor_id|
insertion_point.each do |parent, children|
@@ -134,19 +135,19 @@ def check_ancestry_integrity!
all.each do |node|
# ... check validity of ancestry column
if node.errors.invalid? node.class.ancestry_column
- raise AncestryIntegrityException.new "Invalid format for ancestry column of node #{node.id}: #{node.read_attribute node.ancestry_column}."
+ raise AncestryIntegrityException.new("Invalid format for ancestry column of node #{node.id}: #{node.read_attribute node.ancestry_column}.")
end
# ... check that all ancestors exist
node.ancestor_ids.each do |node_id|
unless exists? node_id
- raise AncestryIntegrityException.new "Reference to non-existent node in node #{node.id}: #{node_id}."
+ raise AncestryIntegrityException.new("Reference to non-existent node in node #{node.id}: #{node_id}.")
end
end
# ... check that all node parents are consistent with values observed earlier
node.path_ids.zip([nil] + node.path_ids).each do |node_id, parent_id|
parents[node_id] = parent_id unless parents.has_key? node_id
unless parents[node_id] == parent_id
- raise AncestryIntegrityException.new "Conflicting parent id in node #{node.id}: #{parent_id || 'nil'} for node #{node_id}, expecting #{parents[node_id] || 'nil'}"
+ raise AncestryIntegrityException.new("Conflicting parent id in node #{node.id}: #{parent_id || 'nil'} for node #{node_id}, expecting #{parents[node_id] || 'nil'}")
end
end
end
@@ -260,7 +261,7 @@ def ancestor_conditions
end
def ancestors depth_options = {}
- self.class.scope_depth(depth_options, depth).scoped :conditions => ancestor_conditions, :order => self.class.ancestry_column
+ self.class.scope_depth(depth_options, depth).ordered_by_ancestry.scoped :conditions => ancestor_conditions
end
def path_ids
@@ -272,7 +273,7 @@ def path_conditions
end
def path depth_options = {}
- self.class.scope_depth(depth_options, depth).scoped :conditions => path_conditions, :order => self.class.ancestry_column
+ self.class.scope_depth(depth_options, depth).ordered_by_ancestry.scoped :conditions => path_conditions
end
def depth
@@ -361,7 +362,7 @@ def descendant_conditions
end
def descendants depth_options = {}
- self.class.scope_depth(depth_options, depth).scoped :conditions => descendant_conditions
+ self.class.ordered_by_ancestry.scope_depth(depth_options, depth).scoped :conditions => descendant_conditions
end
def descendant_ids depth_options = {}
@@ -374,7 +375,7 @@ def subtree_conditions
end
def subtree depth_options = {}
- self.class.scope_depth(depth_options, depth).scoped :conditions => subtree_conditions
+ self.class.ordered_by_ancestry.scope_depth(depth_options, depth).scoped :conditions => subtree_conditions
end
def subtree_ids depth_options = {}
View
@@ -5,11 +5,10 @@ sqlite3:
adapter: sqlite3
database: vendor/plugins/ancestry/test/ancestry_plugin.sqlite3.db
postgresql:
- adapter: postgresql
- username: ancestry_plugin_test
- password: ancestry_plugin_test
- database: ancestry_plugin_test
- min_messages: ERROR
+ adapter: postgresql
+ database: ancestry_performance
+ username: ancestry_performance
+ password: ancestry_performance
mysql:
adapter: mysql
host: localhost

0 comments on commit 48441fb

Please sign in to comment.