

This strategyĭoes not trigger update callbacks for the descendants. :sql All descendants are updated using a single SQL statement. Triggers update callbacks for each descendants nodes :ruby All descendants are updated using the ruby algorithm. :update_strategy Choose the strategy to update descendants nodes (default: `ruby`) Pass symbol to use different column name (default: false) :counter_cache Boolean whether to create counter cache column accessor. :touch Instruct Ancestry to touch the ancestors of a node when it changes, to :primary_key_format Supply a regular expression that matches the format of your primary keyīy default, primary keys only match integers (+) :depth_cache_column Pass in a symbol to store depth cache in a different column Build cache: TreeNode.rebuild_depth_cache! Migrate: add_column, :ancestry_depth, :integer, :default => 0 If you turn depth_caching on for an existing model: :cache_depth Cache the depth of each node in the 'ancestry_depth' column (default: false)

If the deleted node is Root, then rootify the orphan subtree :adopt The orphan subtree is added to the parent of the deleted node :restrict An AncestryException is raised if any children exist :rootify The children of the destroyed node become root nodes :destroy All children are destroyed as well (default) :orphan_strategy Instruct Ancestry what to do with children of a node that is destroyed: :materialized_path2 /1/2/3/, root nodes ancestry=/ :materialized_path (default) 1/2/3, root nodes ancestry=nil :ancestry_format Ancestry format (see Formats below): :ancestry_column Pass in a symbol to store ancestry in a different column The has_ancestry method supports the following options: The yellow nodes are those returned by the method.ġ. The node with the large border is the reference node (the node from which the navigation method is invoked.) # app/models/ class 'Stinky', :parent => TreeNode.create!(:name => 'Squeeky').Ĭhildren can be created through the children relation on a node: :name => 'Stinky'. This means you can't have an tree with a depth that is too great (~> 900 items at most). NOTE: A Btree index (as is recommended) has a limitaton of 2704 characters for the ancestry column. Not consistent across operating systems but other databases do not have this same The important take away is postgres sort order is Set the environment variable COLLATE_SYMBOLS=false. If you opt out of this, and are trying to run tests on postgres, you may need to It also works better for the uuid case as well.Īlternatively, if you create a text_pattern_ops index for your postgresql column, subtree selection will use an efficient index for you regardless of whether you created the column with POSIX encoding. Since this column will just contain numbers and slashes, it works muchīetter. This is a more primitive encoding and just comparesīytes. Depending upon your comfort with databases, you may want to create the column
