Results 1 to 8 of 8

Thread: [CLOSED] Associating a model to itself

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Ext JS Premium Member
    Join Date
    Mar 2011
    Posts
    54

    Default [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".

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    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.

  3. #3
    Ext JS Premium Member
    Join Date
    Mar 2011
    Posts
    54

    Default

    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.

  4. #4
    Ext JS Premium Member
    Join Date
    Mar 2011
    Posts
    54

    Default

    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

  5. #5
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    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.

  6. #6
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258

    Default

    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.

  7. #7
    Ext JS Premium Member
    Join Date
    Mar 2011
    Posts
    54

    Default

    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

  8. #8
    Ext JS Premium Member
    Join Date
    Mar 2011
    Posts
    54

    Default

    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.

Similar Threads

  1. [CLOSED]cannot extend Model having associations (PR5)
    By christophe.geiser in forum Ext:Bugs
    Replies: 3
    Last Post: 31 Mar 2011, 12:05 AM
  2. [CLOSED]Error in Ext.data.Model.load ?
    By htammen in forum Ext:Bugs
    Replies: 1
    Last Post: 7 Mar 2011, 8:48 PM
  3. [CLOSED]Model.save also fails...
    By icflorescu in forum Ext:Bugs
    Replies: 3
    Last Post: 17 Feb 2011, 7:44 PM
  4. Associating a loadmask to a textarea
    By michaelc in forum Ext 2.x: Help & Discussion
    Replies: 0
    Last Post: 23 Nov 2009, 3:06 PM
  5. [2.1][CLOSED] Column Model css not used in GridView
    By simonellistonball in forum Ext 2.x: Bugs
    Replies: 4
    Last Post: 26 Sep 2008, 6:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •