nested-sets

Ruby on Rails - Awesome nested set plugin

天大地大妈咪最大 提交于 2019-12-03 13:42:43
问题 Is there a simple way to display the entire nested set when using this plugin? What I would like to do is display an unordered list of root nodes with another unordered list inside each child that also contains children and so on? Any advice appreciated. Thanks. 回答1: There are a few ways to do this. The simplest is to just start with the roots and parse each node and it's children. The first thing I'd do is make a partial for a the node markup: _your_model.html.erb <li> <%= your_model.name %>

get all products of category and child categories (rails, awesome_nested_set)

余生颓废 提交于 2019-12-03 13:12:11
having an e-commerce application under development i am trying to get my head around the following problem: I have my categories realized through the awesome_nested_set plugin. If I list my articles through selecting one category everything works fine, but for some links I want to show all the products of one category and the products of its child categories. here is the controller code that works fine with only one category: # products_controller.rb def index if params[:category] @category = Category.find(params[:category]) #@products = @category.product_list @products = @category.products

Finding breadcrumbs for nested sets

丶灬走出姿态 提交于 2019-12-03 09:16:23
I'm using nested sets (aka modified preorder tree traversal) to store a list of groups, and I'm trying to find a quick way to generate breadcrumbs (as a string, not a table) for ALL of the groups at once. My data is also stored using the adjacency list model (there are triggers to keep the two in sync). So for example: ID Name ParentId Left Right 0 Node A 0 1 12 1 Node B 0 2 5 2 Node C 1 3 4 3 Node D 0 6 11 4 Node E 3 7 8 5 Node F 4 9 9 Which represents the tree: Node A Node B Node C Node D Node E Node F I would like to be able to have a user-defined function that returns a table: ID

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

早过忘川 提交于 2019-12-03 09:07:29
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: Background: Currently the system has a fixed hierarchy in place which is State->County->City->User

Which Hierarchical model should I use? Adjacency, Nested, or Enumerated?

倾然丶 夕夏残阳落幕 提交于 2019-12-03 05:19:19
问题 I have a table which contains a location of all geographical locations in the world and their relationships. Here is a example that shows the hierarchy. You will see that the data is actually stored as all three Enumerated Path Adjacency list Nested Set The data obviously never changes either. Below is an example of direct ancestors of the location Brighton in England which has a woeid of 13911. Table: geoplanet_places (Has 5.6million rows) Large Image: http://tinyurl.com/68q4ndx I then have

Improving scalability of the modified preorder tree traversal algorithm

二次信任 提交于 2019-12-03 05:17:45
问题 I've been thinking about the modified preorder tree traversal algorithm for storing trees within a flat table (such as SQL). One property I dislike about the standard approach is that to insert a node you have to touch (on average) N/2 of the nodes (everything with left or right higher than the insert point). The implementations I've seen rely on sequentially numbered values. This leaves no room for updates. This seems bad for concurrency and scaling. Imagine you have a tree rooted at the

Ruby on Rails - Awesome nested set plugin

我是研究僧i 提交于 2019-12-03 03:38:33
Is there a simple way to display the entire nested set when using this plugin? What I would like to do is display an unordered list of root nodes with another unordered list inside each child that also contains children and so on? Any advice appreciated. Thanks. There are a few ways to do this. The simplest is to just start with the roots and parse each node and it's children. The first thing I'd do is make a partial for a the node markup: _your_model.html.erb <li> <%= your_model.name %> <% unless your_model.children.empty? %> <ul> <%= render your_model.children %> </ul> <% end %> </li> Next

Breadcrumb navigation with Doctrine NestedSet

社会主义新天地 提交于 2019-12-02 22:22:21
问题 I have a model that implements NestedSet behaviour: Page: actAs: NestedSet: hasManyRoots: true rootColumnName: root_id columns: slug: string(255) name: string(255) Example fixtures: Page: NestedSet: true Page_1: slug: slug1 name: name1 Page_2: slug: slug2 name: name2 children: Page_3: slug: page3 name: name3 I am looking for the easiest way to implement breadcrumb navigation (trail). For example, for Page_3 navigation will look like this: <a href="page2">name2</a> > <a href="page2/page3>name3

SQL Server Tree Hierarchy and Nested Sets with Duplicate Record ids

怎甘沉沦 提交于 2019-12-01 21:35:00
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 doing this would be to follow this article - Improve hierarchy performance using nested sets and include

MySQL & nested set: slow JOIN (not using index)

耗尽温柔 提交于 2019-12-01 15:43:21
问题 I have two tables: localities: CREATE TABLE `localities` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(100) NOT NULL, `type` varchar(30) NOT NULL, `parent_id` int(11) DEFAULT NULL, `lft` int(11) DEFAULT NULL, `rgt` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `index_localities_on_parent_id_and_type` (`parent_id`,`type`), KEY `index_localities_on_name` (`name`), KEY `index_localities_on_lft_and_rgt` (`lft`,`rgt`) ) ENGINE=InnoDB; locatings: CREATE TABLE `locatings` ( `id` int(11) NOT