nested-sets

Laravel: seeding a nested set table with Faker

我的未来我决定 提交于 2021-02-08 07:28:36
问题 I'm using Kalnoy/Nestedset and trying to seed my comments table using faker, but get "Array to string conversion" error. The comment table looks like this: Schema::create('comments', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('user_id'); $table->unsignedInteger('post_id'); $table->text('body'); $table->timestamps(); $table->nestedSet(); }); The comment factory: use Faker\Generator as Faker; $factory->define( App\Models\Comment::class, function (Faker

Nested Set Query to retrieve all ancestors of each node

淺唱寂寞╮ 提交于 2021-01-20 18:24:30
问题 I have a MySQL query that I thought was working fine to retrieve all the ancestors of each node, starting from the top node, down to its immediate node. However when I added a 5th level to the nested set, it broke. Below are example tables, queries and SQL Fiddles: Four Level Nested Set: CREATE TABLE Tree (title varchar(20) PRIMARY KEY, `tree` int, `left` int, `right` int); INSERT Tree VALUES ("Food", 1, 1, 18), ('Fruit', 1, 2, 11), ('Red', 1, 3, 6), ('Cherry', 1, 4, 5), ('Yellow', 1, 7, 10),

SQL Server Tree Hierarchy and Nested Sets with Duplicate Record ids

两盒软妹~` 提交于 2020-01-30 05:56:08
问题 Given that I have this resultset structure (superfluous fields have been stripped) Id | ParentId | Name | Depth ---------------------------- is it possible to have the records returned in tree order i.e. Parent then Children , if a Child is a Parent , then their Children , if not then Sibling , etc? For example, Id | ParentId | Name | Depth ---------------------------- 1 NULL Major 1 2 1 Minor 2 3 1 Minor 2 4 3 Build 3 5 3 Build 3 6 1 Minor 2 /* etc, etc */ The only way that I can think of

PHP: Formatting multi-dimensional array as HTML?

久未见 提交于 2020-01-15 12:09:34
问题 I have tried to get my head around building a recursive function to handle formatting of a unknown depth multi-dimensional array to HTML and nested Divs. I thought that it should be a piece of cake, but no. Here's what I have come up with this far: function formatHtml($array) { $var = '<div>'; foreach ($array as $k => $v) { if (is_array($v['children']) && !empty($v['children'])) { formatHtml($v['children']); } else { $var .= $v['cid']; } } $var.= '</div>'; return $var; } And here's my array:

PHP: Formatting multi-dimensional array as HTML?

本小妞迷上赌 提交于 2020-01-15 12:09:22
问题 I have tried to get my head around building a recursive function to handle formatting of a unknown depth multi-dimensional array to HTML and nested Divs. I thought that it should be a piece of cake, but no. Here's what I have come up with this far: function formatHtml($array) { $var = '<div>'; foreach ($array as $k => $v) { if (is_array($v['children']) && !empty($v['children'])) { formatHtml($v['children']); } else { $var .= $v['cid']; } } $var.= '</div>'; return $var; } And here's my array:

Part Database - Network Model / Hierachal Model / Nested Sets / Acyclic Graphs. Which is right here?

扶醉桌前 提交于 2020-01-05 15:36:11
问题 We are using PHP / SQL to build a parts database which will output as a tree structure. After plunging head first into the coding with the nested sets model we realised that we needed to adjust the model to allow for multiple parents. Effectively, every child can have more than one parent, and every parent can have more than one child, but each node cannot be its own relative. We want to link a collection of parts (A) to a parent part and create a larger part (B) whilst keeping the original

Have you extended nested sets for hierarchical data modeling involving multiple parent nodes for a child node? What are your experiences?

风格不统一 提交于 2020-01-01 03:27:07
问题 I am looking to use this concept in one of my upcoming project. More info: Managing Hierarchical Data in MySQL. Please share your experiences good or bad with examples. I am adding more information to make it more broad: I have child items that can have more than one parent (example: a user can belong to city and also a group called UserDefinedRegion), which the typical hierarchical models do not support, whether it is adjacency list or nested sets. I am pasting the use case here for clarity:

How to display a tree from the information stored in database?

可紊 提交于 2019-12-23 04:19:10
问题 Using Nested Sets, it's possible to store a tree in a relational db. How to display the tree, with the correct relations of each node? For example, each node's left and right values are stored in db. How to display this tree in java based on the nested set data? How to display the correct hierarchy and relations of each node only with the information stored in DB? How to display the path from the root to the node which has no children, for instance, A->B->D, A->C, A->E->F. EIDT: Based only on

Nested Set indices & performance

喜欢而已 提交于 2019-12-22 13:56:14
问题 I'm having some troubles understanding what indices to use on a Nested-Set model. The query is: SELECT `node`.`id`,(COUNT(parent.id) - 1) AS `depth`,`name` FROM `categories` AS `parent` INNER JOIN `categories` AS `node` ON (`node`.`lft` BETWEEN parent.lft AND parent.rgt) INNER JOIN `filebank_categories` ON (`node`.`id` = `filebank_categories`.`category_id` AND `filebank_categories`.`filebank_id` = 136) INNER JOIN `categories_names` ON (`categories_names`.`category_id` = `node`.`id` AND

How do you sort a tree stored using the nested set model?

会有一股神秘感。 提交于 2019-12-20 09:03:05
问题 When I refer to nested set model I mean what is described here. I need to build a new system for storing "categories" (I can't think of better word for it) in a user defined hierarchy. Since the nested set model is optimized for reads instead of writes, I decided to use that. Unfortunately during my research and testing of nested sets, I ran into the problem of how do I display the hierarchical tree with sorted nodes. For example if I have the hierarchy: root finances budgeting fy08 projects