Results 1 to 4 of 4

Thread: Yet another bug in Extjs? (BelongsToAssociation)

  1. #1
    Sencha User
    Join Date
    Jun 2011
    Location
    Kyiv, Montreal
    Posts
    124

    Default Yet another bug in Extjs? (BelongsToAssociation)

    Hi,

    BelongsToAssociation doesn't work for me

    Here is my code:
    Code:
    Ext.define('Category', {
        extend: 'Ext.data.Model',
        fields: [
            { name: 'id',   type: 'int' },
            { name: 'name', type: 'string' }
        ],
        associations: [{
             type: "hasMany", model:"Product"
        }]
    });
    
    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' }
        ]
    });
    Now let's create new Category
    Code:
    var c = new Category({
    id: 1, name: "Cat1"
    },1);
    And load new products
    Code:
    c.products().loadData([{
        id:1,
        category_id:1,
        name:"prod1"
    ])
    Now, lets get category for product
    Code:
    h=c.products().first();
    h.getCategory(function(a){
       console.log(a)
    })
    Here is result
    TypeError: Cannot call method 'indexOf' of undefined

    So what's the problem? The most part of this code I've gotten from Documentation

    Thanks

  2. #2
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379

    Default

    What Ext JS 4 version are you using? The error I am getting is it's trying to load the model via model.load but there isn't a proxy so it's erroring out.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  3. #3
    Sencha User
    Join Date
    Jun 2011
    Location
    Kyiv, Montreal
    Posts
    124

    Default

    I will try to ask question in different way,
    take a look,
    my products-store is loaded
    I have instance of category-model,

    So why product.getCategory -- should sent an Ajax-request, why it cannot return the already created instance of the Category Model?

  4. #4
    Touch Premium Member
    Join Date
    Dec 2007
    Location
    Ireland
    Posts
    65

    Default

    + 1 Extjs 4.1.1 same issue.

Posting Permissions

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