nested-sets

Mysql: Optimizing finding super node in nested set tree

♀尐吖头ヾ 提交于 2019-12-18 11:13:29
问题 I have hierarchical data in a nested set model (table:projects): My table (projects): id, lft, rgt 1, 1, 6 2, 2, 3 3, 4, 5 4, 7, 10 5, 8, 9 6, 11, 12 7, 13, 14 ... Pretty printed: 1 2 3 4 5 6 7 To find the nearest super node of node 3 (knowing its lft value), i can do explain SELECT projects.* FROM projects WHERE 4 BETWEEN projects.lft AND projects.rgt Which gives me a list of the projects in the path down to node 3. Then by grouping and finding MAX(projects.lft) of the results, i get the

Mysql: Optimizing finding super node in nested set tree

ぐ巨炮叔叔 提交于 2019-12-18 11:13:01
问题 I have hierarchical data in a nested set model (table:projects): My table (projects): id, lft, rgt 1, 1, 6 2, 2, 3 3, 4, 5 4, 7, 10 5, 8, 9 6, 11, 12 7, 13, 14 ... Pretty printed: 1 2 3 4 5 6 7 To find the nearest super node of node 3 (knowing its lft value), i can do explain SELECT projects.* FROM projects WHERE 4 BETWEEN projects.lft AND projects.rgt Which gives me a list of the projects in the path down to node 3. Then by grouping and finding MAX(projects.lft) of the results, i get the

Getting nested set model into a <ul> but hiding “closed” subtrees

a 夏天 提交于 2019-12-17 22:53:19
问题 Based on Getting a modified preorder tree traversal model (nested set) into a <ul> One of answers gave right code to display full tree. What i need is to always show first level (depth=0) and siblings+childrens for active list item. Goal is to expand visible part of tree when user selects list item which is parent for more list items. So, if i got this list: 1. item 2. item 2.1. item 2.2. item 2.2.1. item 2.2.2. item 2.2.3. item 2.3. item 2.4. item 2.4.1. item 2.4.2. item 3. item 4. item 4.1.

Searching for the best PHP nested sets class (PEAR class excluded)

断了今生、忘了曾经 提交于 2019-12-17 18:30:33
问题 I'm looking for a PHP (with MYSQL) nested sets class with all needed functions. For example: createLeftNode, createRightNode,createRootNode, createSubNode,deleteNode and moveTree . Not only 1 left, 1 right, 1 up and 1 down but also a part of a tree in a nother tree. Thanks! 回答1: Well nested sets are great if you are working with hierarchical data. It's much more complex to implement it only with php arrays especially if you want to save these information in a database. you could try this on.

Move node in nested set

自闭症网瘾萝莉.ら 提交于 2019-12-17 17:38:06
问题 I'd need a MySQL query that moves a node and all its children within a nested set. I found this site, but that function just seems so illogical - there's no universeid or treeid in a nested set model, and the code itself is just longer than what feels required. The only extra column I've got in the table is parent . I couldn't just remove and add the node again since it will loose its ID. 回答1: I see, that this topic is quite old, but anyway it's still unanswered. I got here from Google, and

How do you convert a parent-child (adjacency) table to a nested set using PHP and MySQL?

放肆的年华 提交于 2019-12-17 17:33:45
问题 I've spent the last few hours trying to find the solution to this question online. I've found plenty of examples on how to convert from nested set to adjacency... but few that go the other way around. The examples I have found either don't work or use MySQL procedures. Unfortunately, I can't use procedures for this project. I need a pure PHP solution. I have a table that uses the adjacency model below: id parent_id category 1 0 Books 2 0 CD's 3 0 Magazines 4 1 Books/Hardcover 5 1 Books/Large

How to render all records from a nested set into a real html tree

删除回忆录丶 提交于 2019-12-17 16:13:52
问题 I'm using the awesome_nested_set plugin in my Rails project. I have two models that look like this (simplified): class Customer < ActiveRecord::Base has_many :categories end class Category < ActiveRecord::Base belongs_to :customer # Columns in the categories table: lft, rgt and parent_id acts_as_nested_set :scope => :customer_id validates_presence_of :name # Further validations... end The tree in the database is constructed as expected. All the values of parent_id , lft and rgt are correct.

Getting a modified preorder tree traversal model (nested set) into a <ul>

早过忘川 提交于 2019-12-17 04:13:05
问题 I am trying to get my data which is hierarchically set up with a tree traversal model into an < ul> in order to show on my site. Here is my code: function getCats($) { // retrieve all children of $parent $query = "SELECT max(rght) as max from t_categories"; $row = C_DB::fetchSingleRow($query); $max = $row["max"]; $result ="<ul>"; $query = "SELECT * from t_categories where lft >=0 and rght <= $max"; if($rs = C_DB::fetchRecordset($query)){ $p_right =""; $p_left =""; $p_diff=""; while($row = C

Nested Set Error undefined method `self_and_descendants' for #<ActiveRecord::Relation:0x52c4a30>

强颜欢笑 提交于 2019-12-13 03:22:47
问题 I am using the Nested_Set gem in my code to sort Categories, Subcategories, and Products. I am trying to limit the depth/level of my nested set to no deeper then 2. Currently I am getting the error Nested Set Error undefined method `self_and_descendants' for #<ActiveRecord::Relation:0x52c4a30> I am trying to create a restraunt menu type style, and am going to attempt to make it drag and drop sortable. Here is my code: Can someone browse it and help me understand this error? Thanks Category.rb

MySQL Error 2014 - Commands out of sync - when trying to call consecutive stored procs

泪湿孤枕 提交于 2019-12-13 03:07:32
问题 I have a hierarchical MySQL table setup using the Nested Set model. I have created a stored proc which allows me to delete an organization. When I try making consecutive calls to the stored proc, I get the following error referring to the second CALL command: 2014 - Commands out of sync; you can't run this command now Here is the SQL I am running: SELECT @id := id, @parent_id := parent_id FROM organization WHERE name = 'TESTDEAL'; CALL deleteOrg(@id); CALL deleteOrg(@parent_id); And here is