1. #1
    Sencha User
    Join Date
    Sep 2007
    Posts
    88
    Answers
    7
    Vote Rating
    2
    tm8747a is on a distinguished road

      0  

    Default Answered: belongsTo association returns a model of the wrong class

    Answered: belongsTo association returns a model of the wrong class


    I have the following models (edited for brevity):

    Code:
    Ext.define('NP.model.user.Userprofile', {
        extend: 'Ext.data.Model',
        
        idProperty: 'userprofile_id',
        fields: [
            { name: 'userprofile_id', type: 'int' },
            { name: 'userprofile_username' }
        ]
    });
    
    Ext.define('NP.model.property.UnitTypeVal', {
        extend: 'Ext.data.Model',
        
        idProperty: 'unittype_val_id',
        fields: [
            { name: 'unittype_val_id', type: 'int' },
            { name: 'unittype_id', type: 'int' },
            { name: 'unittype_val_val' }
        ]
    });
    
    Ext.define('NP.model.property.UnitType', {
        extend: 'Ext.data.Model',
        
        requires: [
            'NP.model.user.Userprofile',
            'NP.model.property.UnitTypeVal'
        ],
    
        idProperty: 'unittype_id',
        fields: [
            { name: 'unittype_id', type: 'int' },
            { name: 'unittype_name' },
            { name: 'unittype_updated_by', type: 'int' }
        ],
    
        belongsTo: {
            model         : 'NP.model.user.Userprofile',
            associationKey: 'lastUpdatedUser',
            getterName    : 'getLastUpdatedUser',
            foreignKey    : 'unittype_updated_by',
            primaryKey    : 'userprofile_id'
        },
        hasMany  : {
            model     : 'NP.model.property.UnitTypeVal',
            name      : 'vals',
            foreignKey: 'unittype_id',
            primaryKey: 'unittype_id'
        }
    });
    The hasMany relationship is working fine. The belongsTo, however, is pulling the wrong model. As in, if I do something like myRecord.getLastUpdatedUser() I do get a record back, except it's from some other model. The model it's giving me back was a model from another hasMany relationship for another model, so I tried removing it to see what happened. After doing that, I just get back some other random model that's not even used in any other relationship.

    Any ideas???

  2. OK, figured this one out. I'll share just in case somebody runs into this too. Basically, turns out simplifying the code for brevity was a mistake, since I took out a key element. I was actually not using Ext.data.Model, but rather a class extending it that fixed a bug where using load() on the model doesn't take into account the idProperty configuration. So that extended class overrode the load function in statics, as posted on StackOverflow by somebody who obviously meant well. Problem is, looks like that screws something else up because as soon as I switched to Ext.data.Model, everything worked fine. Kind of a pain, since I can't upgrade to a new version that may fix the idProperty bug, and I don't really want to update the ExtJS source instead. But at least I've figured this issue out.

  3. #2
    Sencha User
    Join Date
    Sep 2007
    Posts
    88
    Answers
    7
    Vote Rating
    2
    tm8747a is on a distinguished road

      0  

    Default


    OK, figured this one out. I'll share just in case somebody runs into this too. Basically, turns out simplifying the code for brevity was a mistake, since I took out a key element. I was actually not using Ext.data.Model, but rather a class extending it that fixed a bug where using load() on the model doesn't take into account the idProperty configuration. So that extended class overrode the load function in statics, as posted on StackOverflow by somebody who obviously meant well. Problem is, looks like that screws something else up because as soon as I switched to Ext.data.Model, everything worked fine. Kind of a pain, since I can't upgrade to a new version that may fix the idProperty bug, and I don't really want to update the ExtJS source instead. But at least I've figured this issue out.

Tags for this Thread

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar