Results 1 to 4 of 4

Thread: Has Many Association Woes

  1. #1
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    10

    Default Answered: Has Many Association Woes

    I am attempting to recreate this example in extjs 6:
    http://moduscreate.com/associations-in-ext-js-5/

    MyApp is the namespace in my workspace, so:

    Code:
    Ext.define('MyApp.model.Customer', {
        extend : 'Ext.data.Model',
        fields : [
            'name'
        ]
    });
    
    Ext.define('MyApp.model.Address', {
        extend : 'Ext.data.Model',
        requires: [
            'MyApp.model.Customer'
        ],
        fields : [
            { name : 'address'},
            { name : 'customerId', reference : 'MyApp.model.Customer'}
        ]
    });
    
    Ext.define('MyApp.store.Customers', {
        extend   : 'Ext.data.Store',
        model    : 'MyApp.model.Customer',
        autoLoad : true,
        proxy : {
            type : 'ajax',
            url  : 'customers'
        }
    });
    The data that is served by the url customers:

    Code:
    [
      {
        "id": 1,
        "name": "Modus Create",
        "addresses": [
          {
            "id": 1,
            "address": "Reston, VA"
          },
          {
            "id": 2,
            "address": "Providence, RI"
          }
        ]
      }
    ]

    The "raw" data for addresses is in the record, but there is no getter for addresses which tells me the association is not working:

    Screen Shot 2015-05-06 at 12.36.29 PM.png

    There are only 2 differences I see in my code and the example, ext 6, and the namespace. I also attempted to add a require to the address model.

    What am I missing?

    Thanks in advance!

  2. See: http://docs.sencha.com/extjs/5.1/cor...l#Associations

    Specifically the part about namespace.

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

    Default

    See: http://docs.sencha.com/extjs/5.1/cor...l#Associations

    Specifically the part about namespace.
    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.

  4. #3
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    10

    Default

    Thank you for the information, that was helpful. After reading that over I see that I was missing the base model, and now my example works. Though, I have a follow-up question:

    When the framework parses out the association's data, for example a User has many Post, where in the data the association looks like:

    Code:
    {
        "success": true,
        "user": [{
            "id": 1,
            "name": "Philip J. Fry",
            "posts": [{
                "title": "Post 1"
            },{
                "title": "Post 2"
            },{
                "title": "Post 3"
            }]
        }]
    }
    The framework looks for the posts property to populate the association. If I were to have a camel cased entity name, for example, PrintProject has many PrintComponent, would the framework look for the associated data in the property printComponents or printcomponents? I have replicated the same structure as the initial Customers example, but the association fails to load.

    Thanks again!

  5. #4
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    10

    Default

    Ok I have found the answer myself, looking at the schema entities associations property, I can see that it looks like this:

    projectPrintComponent

    For anyone also looking into this I would also suggest looking here:

    http://docs-origin.sencha.com/extjs/....schema.Schema

Similar Threads

  1. [CLOSED] model subclass association bug - duplicate association
    By mderer in forum Ext 5: Bugs
    Replies: 3
    Last Post: 31 Jul 2014, 5:50 AM
  2. hasMany association woes
    By horcle_buzz in forum Sencha Touch 2.x: Discussion
    Replies: 2
    Last Post: 12 May 2014, 11:09 AM
  3. Replies: 1
    Last Post: 13 Mar 2014, 6:20 AM
  4. Replies: 0
    Last Post: 15 May 2012, 6:31 PM
  5. Replies: 2
    Last Post: 10 Apr 2012, 10:27 AM

Tags for this Thread

Posting Permissions

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