Results 1 to 6 of 6

Thread: Associations not working

    Looks like we can't reproduce the issue or there's a problem in the test case provided.
  1. #1
    Sencha User
    Join Date
    Jun 2008
    Posts
    157

    Default Associations not working

    I'm trying to use the associations in the models, as said in the docs, but it seems they are not working.
    I'm using the example of the belongsTo association. The code is this:
    Code:
    Ext.define('Category', {     
    extend: 'Ext.data.Model',     
    fields: [         
    { name: 'id',   type: 'int' },         
    { name: 'name', type: 'string' }     
    ] });  
    
    Ext.define('Product', {     
    extend: 'Ext.data.Model',     
    fields: [         
    { name: 'id',          type: 'int' },         
    { name: 'category_id', type: 'int' },         
    { name: 'name',        type: 'string' }     
    ],
    associations: { type: 'belongsTo', model: 'Category' } 
    });
    After that I run:
    Code:
    var product = new Product({     
    id: 100,     
    category_id: 20,     
    name: 'Sneakers' });  
    product.getCategory
    And the getCategory function isn't defined.

    I'm using ext 4.0.2a. Is there something I'm missing?

  2. #2
    Sencha User mberrie's Avatar
    Join Date
    Feb 2011
    Location
    Bangkok, Thailand
    Posts
    506

    Default

    Code:
    associations: [{ type: 'belongsTo', model: 'Category' }]

  3. #3
    Sencha User
    Join Date
    Jun 2008
    Posts
    157

    Default

    FACEPALM!
    ok, correct the documentation then....

  4. #4
    Sencha User mberrie's Avatar
    Join Date
    Feb 2011
    Location
    Bangkok, Thailand
    Posts
    506

    Default

    who.. me?

    Pls report bugs in the docs here

  5. #5
    Sencha User
    Join Date
    Jun 2008
    Posts
    157

    Default

    oops, no, I thought you were from the sencha team. I already posted it in the documentation bugs.

  6. #6
    Sencha User mberrie's Avatar
    Join Date
    Feb 2011
    Location
    Bangkok, Thailand
    Posts
    506

    Default

    haha, no problem!

    Thanks for reporting the bug!

    Obviously some copy/paste issue in the docs, the comment in the example refers to the 'belongsTo shortcut' which doesn't expect an array. The code, however, uses the 'associations' property which requires an array.

    Code:
      belongsTo: 'Category',
    
      associations: [ { type:'belongsTo', model: 'Category' } ]

Posting Permissions

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