-
models associations
hi.
i have 3 mysql tables:
---
a
id|name
b
id|name
a_b
a_id|b_id
---
i create 3 models:
Code:
Ext.define('a', {
extend: 'Ext.data.Model',
fields: ['id', 'name']
});
Ext.define('b', {
extend: 'Ext.data.Model',
fields: ['id', 'name']
});
Ext.define('a_b', {
extend: 'Ext.data.Model',
fields: ['a_id', 'b_id']
});
i need to get all "b" for model "a" defined in the model "a_b", and i need to get all "a" for model "b" defined in the model "a_b"
please help
-
-
I followed the instructions but I did not succeed.
now my models:
Code:
Ext.define('a', {
extend: 'Ext.data.Model',
fields: ['id', 'name'],
associations: [
{type: 'hasMany', model: 'a_b', name: 'bs', foreignKey: 'a_id',},
]
});
Ext.define('b', {
extend: 'Ext.data.Model',
fields: ['id', 'name'],
associations: [
{type: 'hasMany', model: 'a_b', name: 'as', foreignKey: 'b_id',},
]
});
Ext.define('a_b', {
extend: 'Ext.data.Model',
fields: ['a_id', 'b_id']
});
please help with code
-
Doing fine
You seem to be doing fine.
Now you'll want to define a #proxy for each of your models.
Code:
Ext.define('a', {
extend: 'Ext.data.Model',
fields: ['id', 'name'],
proxy: {
type: 'ajax',
url: '/a.json',
reader: {
type: 'json'
}
},
associations: [
{type: 'hasMany', model: 'a_b', name: 'bs', foreignKey: 'a_id',},
]
});
Ext.define('b', {
proxy: {
type: 'ajax',
url: '/b.json',
reader: {
type: 'json'
}
},
extend: 'Ext.data.Model',
fields: ['id', 'name'],
associations: [
{type: 'hasMany', model: 'a_b', name: 'as', foreignKey: 'b_id',},
]
});
Ext.define('a_b', {
proxy: {
type: 'ajax',
url: '/a_b.json',
reader: {
type: 'json'
}
},
extend: 'Ext.data.Model',
fields: ['a_id', 'b_id']
});
-
Also remove commas at the ends of association strings. It's just wrong.