PDA

View Full Version : TreePanel with recursive Model



bradleyman
25 Jun 2012, 12:27 PM
I have the following data model (pseudo code):

Person
fullName: string
children: Array of Person objects

This looks to me like it should be modeled using a HasManyAssociation, so I've defined the model as such:

fields: [ {fullName:'name', type:'string'} ],
hasMany: [ {model:'full.path.to.Person.model', name:'children', associationKey:'children'} ]

I have multiple nested Person records defined in a json file. This file is then read in via an ajax proxy created by a Person store. This Person store is a Tree Store, because I'm ultimately trying to display this nested Person data in a TreePanel.

While the root object returned after the Person store loads is of the appropriate Person model type, the children of that object are not coming back as Person objects. This leads me to believe that the HasManyAssociation is not correctly working (translating the incoming data to Person objects).

Note that I do not (and cannot) have a reciprocal BelongsTo relationship. That is, each Person object does not know who its parent is -- only its children.

1. Is it a requirement to mirror HasManyAssociation and BelongsTo associations? Or is it acceptable to have only one or the other (in this case, only to have the HasManyAssociation).

2. Is it possible to use a TreeStore and a recursive HasManyAssociation (linked on the "children" association key -- which is the Reader's default "root" setting) simultaneously?

3. Any other ideas why this HasManyAssociation might be failing?

4. Or am I perhaps mis-diagnosing the problem?

Thank you!