README.md in closure_tree-3.6.0 vs README.md in closure_tree-3.6.1

- old
+ new

@@ -21,11 +21,11 @@ ## Table of Contents - [Installation](#installation) - [Usage](#usage) - [Accessing Data](#accessing-data) -- [Polymorphic hierarchies with STI](#sti) +- [Polymorphic hierarchies with STI](#polymorphic-hierarchies-with-sti) - [Deterministic ordering](#deterministic-ordering) - [FAQ](#faq) - [Testing](#testing) - [Change log](#change-log) @@ -245,11 +245,11 @@ * ```tag.find_all_by_generation(0).to_a``` == ```[tag]``` * ```tag.find_all_by_generation(1)``` == ```tag.children``` * ```tag.find_all_by_generation(2)``` will return the tag's grandchildren, and so on. * ```tag.destroy``` will destroy a node and do <em>something</em> to its children, which is determined by the ```:dependent``` option passed to ```acts_as_tree```. -## <a id="sti"></a>Polymorphic hierarchies with STI +## Polymorphic hierarchies with STI Polymorphic models using single table inheritance (STI) are supported: 1. Create a db migration that adds a String ```type``` column to your model 2. Subclass the model class. You only need to add ```acts_as_tree``` to your base class: @@ -298,41 +298,44 @@ whose sort order column is more than ```self```. These will be ordered properly, so the ```first``` element in scope will be the sibling immediately "after" ```self``` If your ```order``` column is an integer attribute, you'll also have these: -* ```tag.add_sibling_before(sibling_node)``` which will - 1. move ```tag``` to the same parent as ```sibling_node```, - 2. decrement the sort_order values of the nodes before the ```sibling_node``` by one, and - 3. set ```tag```'s order column to 1 less than the ```sibling_node```'s value. +* ```node1.prepend_sibling(node2)``` which will + 1. set ```node2``` to the same parent as ```node1```, + 2. set ```node2```'s order column to 1 less than ```node1```'s value, and + 3. decrement the order_column of all children of node1's parents whose order_column is <>>= node2's new value by 1. -* ```tag.add_sibling_after(sibling_node)``` which will - 1. move ```tag``` to the same parent as ```sibling_node```, - 2. increment the sort_order values of the nodes after the ```sibling_node``` by one, and - 3. set ```tag```'s order column to 1 more than the ```sibling_node```'s value. +* ```node1.append_sibling(node2)``` which will + 1. set ```node2``` to the same parent as ```node1```, + 2. set ```node2```'s order column to 1 more than ```node1```'s value, and + 3. increment the order_column of all children of node1's parents whose order_column is >= node2's new value by 1. ```ruby + root = OrderedTag.create(:name => "root") a = OrderedTag.create(:name => "a", :parent => "root") b = OrderedTag.create(:name => "b") c = OrderedTag.create(:name => "c") +# We have to call 'root.reload.children' because root won't be in sync with the database otherwise: + a.append_sibling(b) -root.children.collect(&:name) +root.reload.children.collect(&:name) => ["a", "b"] a.prepend_sibling(b) -root.children.collect(&:name) +root.reload.children.collect(&:name) => ["b", "a"] a.append_sibling(c) -root.children.collect(&:name) -=> ["a", "c", "b"] +root.reload.children.collect(&:name) +=> ["b", "a", "c"] b.append_sibling(c) -root.children.collect(&:name) -=> ["a", "b", "c"] +root.reload.children.collect(&:name) +=> ["b", "c", "a"] ``` ## FAQ ### Does this gem support multiple parents? @@ -350,15 +353,22 @@ * The latest Rails 3.0, 3.1, and 3.2 branches, and * MySQL, PostgreSQL, and SQLite. ## Change log +### 3.6.1 + +* Fixed [issue 20](https://github.com/mceachen/closure_tree/issues/20), which affected + deterministic ordering when siblings where different STI classes. Thanks, [edwinramirez](https://github.com/edwinramirez)! + ### 3.6.0 -* Added support for: - * ```:hierarchy_class_name``` as an option - * ActiveRecord::Base.table_name_prefix - * ActiveRecord::Base.table_name_suffix +Added support for: +* ```:hierarchy_class_name``` as an option +* ActiveRecord::Base.table_name_prefix +* ActiveRecord::Base.table_name_suffix + +This addresses [issue 21](https://github.com/mceachen/closure_tree/issues/21). Thanks, [Judd Blair](https://github.com/juddblair)! ### 3.5.2 * Added ```find_all_by_generation``` for [feature request 17](https://github.com/mceachen/closure_tree/issues/17).