Thank you for reporting this bug. We will make it our priority to review this report.
-
Ext JS Premium Member
[CLOSED] Associating a model to itself
ExtJS4 does appear to allow a model to link back to itself. If it does allow such a thing, it is undocumented.
Consider the table "group", which has the following fields:
name
parent_group_id
Where "parent_group_id" links back to "group".
-
Yes, the docs could do with a bit more info about the foreignKey option, I'll update it now.
Twitter - @evantrimboli
Former Sencha framework engineer, available for consulting.
As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.
-
Ext JS Premium Member
When linking back to yourself in a model definition you would include a 'hasMany' and 'belongsTo' declaration inside of the same model.
I think, since 'belongsTo' expects an existing 'hasMany', it fails for one reason or another.
In my previous tests the association was ignored all together. I will attempt to create a test case to illustrate my troubles in a few minutes.
-
Ext JS Premium Member
Alright, in the test case I made its not ignoring the association, but the child group data is not loaded.
http://staging.travelingsports.com/?...rcularModelRef
P.S. Please do not close my bug reports until you're sure I'm wrong. I feel like Sencha is being rather dismissive to me, and I'm just trying to do my job. I often feel like I'm putting in as much work as you are on ExtJS in having to build these test cases just to get a point across. I'm willing to go the distance to help, since your help in turn helps me, but please provide me the courtesy of looking into my reports as though I'm not making things up for the fun of it.
Thanks,
Luke
-
There's a couple of things that don't add up in your test case:
1) You never load the groups() store. By default it won't load automatically, however you can set the autoLoad option on the association.
2) If I override it to load the store, it returns a key group_id, which isn't listed anywhere in your model. Since you explicitly specify a foreignKey value, it won't auto create one as group_id.
Twitter - @evantrimboli
Former Sencha framework engineer, available for consulting.
As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.
-
To clarify, are you trying to do this all in a single load? What are you trying to achieve here?
Twitter - @evantrimboli
Former Sencha framework engineer, available for consulting.
As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.
-
Ext JS Premium Member
Yes, I am trying to load a group and its parent group information in a single load. In our actual usage there are hundreds of records. In the case of menu data, or similar, we might return an entire tree from the server.
As for your prior two statements, I do not completely understand:
1) You mean the "sub-group" association store (group.groups)? My primary concern is "getgroup()", I put "rec.groups()" in there to illustrate that data was not being loaded by either association.
2) I specify the field "group_id" on line 5, and define it as the primary key on line 9, right?
I did notice some typos in my association params overlooked from my copy+paste of our actual code to the test case. I fixed everything I noticed and uploaded again.
As for the params I'm using in those associations, if I'm doing that wrong and that turns out to be the solution, then all the better.. but I've tried a few variations and am lost on what I could be doing wrong.
Thanks,
Luke
-
Ext JS Premium Member
Aha! As it turns out, the association is just fine... all of that works...
You and I were both mistaken about this thread:
http://www.sencha.com/forum/showthre...be-non-uniform
So, associating a model to itself works now, but the server does expect an object for a belongsTo association and an array for a has many.
I have added another post to that thread to explain it in more detail since it seems more relevant to that thread.