Results 1 to 10 of 10

Thread: BelongsTo association bug or my own stupidty ?

    You found a bug! We've classified it as EXTJS-6828 . We encourage you to continue the discussion and to find an acceptable workaround while we work on a permanent fix.
  1. #1
    Touch Premium Member
    Join Date
    Dec 2007
    Location
    Ireland
    Posts
    65

    Default BelongsTo association bug or my own stupidty ?

    Hi folks,

    I need a little help. I can't retrieve belongsTo associated model when using memory proxy.

    EDIT : This is ExtJS 4.1.1 behaviour. In ST 2.0.1.1 example works as expected. But in 2.0.1 there was some similar issue in BelongsTo association. I'm just wondering Sencha Team, do you have some tests to test associations at all ???


    First see my two models and one store.

    Parent Model:
    PHP Code:
    Ext.define('MyApp.model.Parent', {
        
    extend'Ext.data.Model',
        
    uses: [
            
    'MyApp.model.Child'
        
    ],

        
    fields: [
            {
                
    name'id',
                
    persistfalse,
                
    type'string'
            
    },
            {
                
    name'name',
                
    persistfalse,
                
    type'string'
            
    }
        ],

        
    hasMany: {
            
    model'MyApp.model.Child',
            
    name'children'
        
    },

        
    proxy: {
            
    type'memory'
        
    }
    }); 
    Child Model:
    PHP Code:
    Ext.define('MyApp.model.Child', {
        
    extend'Ext.data.Model',
        
    uses: [
            
    'MyApp.model.Parent'
        
    ],

        
    fields: [
            {
                
    name'id',
                
    persistfalse,
                
    type'string'
            
    },
            {
                
    name'name',
                
    persistfalse,
                
    type'string'
            
    }
        ],

        
    belongsTo: {
            
    model'MyApp.model.Parent',
            
    getterName'getParent',
            
    setterName'setParent'
        
    },

        
    proxy: {
            
    type'memory'
        
    }
    }); 
    Children store:
    PHP Code:
    Ext.define('MyApp.store.Children', {
        
    extend'Ext.data.Store',
        
    requires: [
            
    'MyApp.model.Child'
        
    ],

        
    constructor: function(cfg) {
            var 
    me this;
            
    cfg cfg || {};
            
    me.callParent([Ext.apply({
                
    storeId'MyStore',
                
    model'MyApp.model.Child'
            
    }, cfg)]);
        }
    }); 
    Now, little bit of testing
    PHP Code:

    var parent Ext.create('MyApp.model.Parent',{
        
    id'1',  name 'parent1'
    });

    console.log('parent'parent);

    // returns
    // id: "MyApp.model.Parent-ext-record-1"
    // internalId: "ext-record-1"
    // data: Object
    //    id: "1"
    //    name: "parent1"
    // prefect

    var child1 Ext.create('MyApp.model.Child',{
        
    id'1',  name 'child1'
    });

    console.log('child1'child1);

    // returns
    // id: "MyApp.model.Child-ext-record-2"
    // internalId: "ext-record-2"
    // data: Object
    //    id: "1"
    //    name: "child1"
    // excelent

    parent.children().add(child1);

    child1.setParent(parent); // i have tried this too

    // so far so good..

    parent.children().each(function(ch){
          
               
    console.log('child in store'ch);

               
    // returns
               // id: "MyApp.model.Child-ext-record-2"
               // internalId: "ext-record-2"
               // data: Object
               //    id: "1"
               //    name: "child1"
               //    myapp.model.parent_id: "1"
               //    parent_id: "1"
               // ooook

               
    console.log('childs parent in store'ch.getParent());

               
    // returns
               // id: "MyApp.model.Parent-ext-record-3"
               // internalId: "ext-record-3"
               // data: Object
               //    id: ""
               //    name: ""
               // BAAAAANG, FRESH EMPTY RECORD ???, WHY ?
               
    }); 
    So,
    Code:
     ch.getParent()
    is aparently returning fresh record instead of associated one if memory proxy is present. If not, it fails on building url with
    Code:
     Uncaught TypeError: Cannot call method 'indexOf' of undefined / urlAppend
    I have tried all possible hasMany, belongsTo configuration options like foreignKey, instanceName, associationKey.. Nothing worked :-(

    Any help appreciated.

    Thanks.

  2. #2
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,664

    Default

    Does it work if you comment proxy in the above code?
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid MultiSearch Plugin, Grid MultiSort Plugin, Configuring ViewModel Hierarchy


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

    Default

    Unfortunately not.

    ExtJS 4.1.1 without proxy defintition fails with

    Code:
     Uncaught TypeError: Cannot call method 'indexOf' of undefined (in method urlAppend)
    as mentioned above.

    ST 2.0.1.1 works fine without proxy defintion

  4. #4
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,664

    Default

    One more idea, and if that fails then I'm prone to believe it is a bug. "children" can be a "reserved" word in Ext, at least related to tree. I know that we're not talking about trees here, nevertheless, try to rename "children" to something else, perhaps also "parent", e.g. to "master" and "slave" - these are not used in Ext for sure.

    Your config is quite straightforward and I see no reason why it shouldn't work.
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid MultiSearch Plugin, Grid MultiSort Plugin, Configuring ViewModel Hierarchy


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

    Default

    Thanks,

    Same results with master / slave..

    And I have found this.

    http://extjs-tutorials.blogspot.ie/2...ion-rules.html

    Focus on this:

    /* you can call phoneNumber.setContact(contact). This will set contact_id on the phone number, BUT it won't set the contact instance on phonenumber, which is likely a bug: */
    Obviously I'm not the only one having this / similar issue.

  6. #6
    Sencha - Community Support Team jsakalos's Avatar
    Join Date
    Apr 2007
    Location
    Slovakia
    Posts
    27,664

    Default

    Yeah, I also believe it is a bug. Do you want this thread to be moved to Bugs forum?
    Jozef Sakalos, aka Saki

    Education, extensions and services for developers at new http://extjs.eu
    News: Grid MultiSearch Plugin, Grid MultiSort Plugin, Configuring ViewModel Hierarchy


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

    Default

    Yes please. Thanks.

  8. #8
    Sencha - Support Team
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,410

    Default

    Done .. Thank you for the report.

    Scott.

  9. #9
    Sencha User
    Join Date
    Sep 2012
    Posts
    83

    Default

    Any update on this issue?

  10. #10
    Sencha Premium Member
    Join Date
    Dec 2012
    Posts
    6

    Default

    I've the exact same issue, any update on this?

Posting Permissions

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