1

I have a model Banner and a model BannerFormat. A banner has a banner format. To configure a hasOne relationship between banner and banner format, i wrote this :

Ext.define('admin.model.Banner', {
    extend: 'Ext.data.Model',
    config: {
        fields: [
            { name: 'id', type: 'int' },
            { name: 'banner_format_id', type: 'int' },
            'code',
            'active',
            'start_at',
            'end_at'
        ],
        associations: { type: 'hasOne', model: 'admin.model.BannerFormat', getterName: 'getBannerFormat' },
        proxy: {
            type: 'ajax',
            url: '/admin/api_query.php',
            extraParams: {
                table: 'content_banners',
                type: 'GET'
            }
        }
    }
});

And in my bannerFormat model:

Ext.define('admin.model.BannerFormat', {
    extend: 'Ext.data.Model',
    config: {
        fields: ['id', 'format'],
        associations: { type: 'hasMany', model: 'admin.model.Banner' },
        proxy: {
            type: 'ajax',
            url: '/admin/api_query.php',
            extraParams: {
                table: 'content_banner_formats',
                type: 'GET'
            }
        }
    }
});

But when i call banner.getBannerFormat(), i got :

Uncaught TypeError: Object [object Object] has no method 'getBannerFormat'

What did i go wrong?

1 Answer 1

1

Are you creating a banner object and then making the call on it to retrieve the defined associations?

This should work for you:

var banner = Ext.create('admin.model.Banner', {
    id: 100,
    banner_format_id: 20,
    code: 'ABC123',
    active: true,
    start_at: 1,
    end_at: 5
});

banner.getBannerFormat();

Also, you don't need to specify a getterName for the association if you don't want. Sencha will auto-generate a getter function for the association, which follows the format: 'getModelName'. If you removed the getterName from your association, the getter function on the banner model would be the same as what you defined it as: 'getBannerFormat';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.