Opened 14 years ago

Closed 13 years ago

#7243 closed enhancement (duplicate)

Trees and Dojo.Data

Reported by: Goran Miskovic Owned by: Jared Jurkiewicz
Priority: high Milestone: tbd
Component: Data Version: 1.1.1
Keywords: tree, data structure Cc:
Blocked By: Blocking:


Having third way to feed the tree with data would be nice.
When pooling data from database (using mySql) I couldn't grasp convenient way to structure data nor as Direct Nesting nor as References type.
Of course it could be my luck of knowledge but it appears that something like this will be more straight forward:

{ label: 'name',
  identifier: 'name',
   items: [
     { name:'Fruit', type:'category'},
     { name:'Cinammon', type: 'category', _parent: 'Fruit'},
     { name:'Cinammon Roll', type:'poptart', _parent: 'Cinnamon'},
     { name:'Brown Sugar Cinnamon', type:'poptart', _parent: 'Cinnamon' },
     { name:'French Toast', type:'poptart', _parent: 'Cinnamon' },
     { name:'Chocolate', type: 'category'}

If data are stored in a single table than
select name, type, parent from food order by name, parent
would do the work and if data are stored as relational data then union statement would do the trick:
select name, type, parent from (
select name, type, name as parent from food
) union (
select, fr.type, fr.parent
from fruit fr
left join food f on fr.parent =
) union (
select, c.type, c.parent
from cinnamon c
left join fruit fr
on c.parent =
) union ( ...etc

Attachments (1)

dojo_tree.sql (3.0 KB) - added by Goran Miskovic 14 years ago.
Sample my sql data

Download all attachments as: .zip

Change History (6)

Changed 14 years ago by Goran Miskovic

Attachment: dojo_tree.sql added

Sample my sql data

comment:1 Changed 14 years ago by Goran Miskovic

Query example:

SELECT `id`, `parent`, `name`, `type` FROM (
	SELECT `id`, 0 as parent, `name`, `type`
	FROM `food`
) union (
	SELECT `id`, `parent`, `name`, `type` 
	FROM `fruit`
) union (
	SELECT `id`, `parent`, `name`, `type`
	FROM `spices`
)union (
	SELECT `id`, `parent`, `name`, `type` 
	FROM `cinnamon`
) as tree_data

comment:2 Changed 14 years ago by Jared Jurkiewicz

Then why not build a custom data store that can talk to your database and extract information as you need it extracted? is a API for accessing data, and it is intended that users write datastores for custom backend data services and to work over specifc SQL structures and schemas.

comment:3 Changed 14 years ago by Goran Miskovic

Absolutely. I am doing that. :)

I just thought that it is quite common that one of SQL databases would be in the backend. That's why my question is more of conceptual nature than request for specific implementation: Row in result set can not be multidimensional area and in relational tables child is aware of parent and not as in all given examples in which parent is aware of child.

Perhaps the best example of the problem that I am talking about is new model concept implemented on dojo tree (tree/forest). If there is method getParent(item) similar to getLabel(item) and getIdentity(item) almost all problems with dnd, etc would be trivial. One would not need to care if it an item is root or not and create special root cases, etc.

It appears to me that instead of asking: "Does this item have property children? Is it array? If yes get me children." more "natural" would be to ask "Get me array of items that have parent which is equal to my identifier."

In case that you find any of ideas potentially interesting I would gladly post work on SQL tree model.

comment:4 Changed 14 years ago by bill

"Get me array of items that have parent which is equal to my identifier."

Sure, you can do this. Just override the model's getChildren() method. Should be a one-liner.

A data store should be able to get an individual item, and to query the children for a given item... and then you can write a model to connect it to the tree. I'm not sure a custom data store will get you more than QueryReadStore.

The old i18n demo was structured where children pointed to their parents rather than vice-versa, although I changed it recently to connect to a different data store so I guess that's no longer true.

comment:5 Changed 13 years ago by Jared Jurkiewicz

Resolution: duplicate
Status: newclosed

The Tree's extendabl model provides an interface for handling determining what a child of an item is (as noted by Bill), so it is possible to do the reverse direction lookup to build a tree. Therefore closing this as duplicate of that tree feature.

Note: See TracTickets for help on using tickets.