You can clone with
ancestry 1.2.5 , activerecord 3.2.1
I'm generating tree-nodes in an STI-table using ancestry - the source is an XML feed in which the nodes are not ordered.
This leads to a problem when the nodes are created and linked.. they are not necessarily created in a top-down order.
Let's assume my tree is only three levels deep. If I have a node x from the mid-level and do x.children on it.
Order of creation was: Top-node, Leaf-node, MidLevel-node x.
# MidLevel node x:
# this SQL seems incorrect:
SELECT `nodes`.* FROM `nodes` WHERE `nodes`.`ancestry` = 1041096/1041124'
# find the orphaned child:
Node.where("ancestry like '%1041124'")
=> [#<Node id: 1041123, ancestry: "1041124", ...>]
Shouldn't the SQL query in the example above be:
SELECT `nodes`.* FROM `nodes` WHERE `nodes`.`ancestry` LIKE '%/1041124' OR `nodes`.`ancestry` = '1041124'