ExtJs 4.2.2 HasMany Association Bug

Posted By Vitalii | February 19, 2014 | ExtJS 4.2.2
0 3467
This type of association represents a one-to-many relationship between two models.
For example OOP Class has many Properties.

As you can see class properties were not loaded as here. And this is a bug in 4.2.2. Forum thread is here.

See how it works on ExtJS 4.1.1 here.

Js Code

Ext.define('Class', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'id', type: 'int' },
        { name: 'name', type: 'string' }
    ],
    hasMany: {
        model: 'Property',
        name: 'properties',
        associationKey: 'properties',
        primaryKey: 'id',
        foreignKey: 'classId'
    },
    proxy: {
        type: 'rest',
        url: '/api/classes'
    }
});

Ext.define('Property', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'id', type: 'int' },
        { name: 'classId', type: 'int' },
        { name: 'name', type: 'string' }
    ],
    proxy: {
        type: 'rest',
        url: '/api/properties'
    }
});
            

ExtJs 4.1.1 HasMany Association

Posted By Vitalii | February 19, 2014 | ExtJS 4.1.1
0 3143
This type of association represents a one-to-many relationship between two models.
For example OOP Class has many Properties.

See how it works on ExtJS 4.2.2 here.

Js Code

Ext.define('Class', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'id', type: 'int' },
        { name: 'name', type: 'string' }
    ],
    hasMany: {
        model: 'Property',
        name: 'properties',
        associationKey: 'properties',
        primaryKey: 'id',
        foreignKey: 'classId'
    },
    proxy: {
        type: 'rest',
        url: '/api/classes'
    }
});

Ext.define('Property', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'id', type: 'int' },
        { name: 'classId', type: 'int' },
        { name: 'name', type: 'string' }
    ],
    proxy: {
        type: 'rest',
        url: '/api/properties'
    }
});
            

ExtJs 4.1: Read complex json with hasOne association

Posted By Vitalii | September 15, 2012 | ExtJS 4.1.0
0 4285
Ext.data.association.HasOne - represents a one to one association with another model.
The owner model is expected to have a foreign key which references the primary key of the associated model

Js Code

Ext.define('User', {
    extend: 'Ext.data.Model',
    fields: ['id', 'name'],
    associations: [{ type: 'hasOne', model: 'Status', associationKey: 'status'}]
});

Ext.define('Status', {
    extend: 'Ext.data.Model',
    fields: [
        { name: 'id', type: 'int' },
        { name: 'title', type: 'string', mapping: 'st_title' }
    ]
});