Hybrid View
-
19 Aug 2011 12:54 PM #1
Unanswered: models associations
Unanswered: models associations
hi.
i have 3 mysql tables:
---
a
id|name
b
id|name
a_b
a_id|b_id
---
i create 3 models:
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"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'] });
please help
-
20 Aug 2011 7:22 AM #2Sencha - Services Team
- Join Date
- May 2007
- Location
- Munich (Germany)
- Posts
- 2,292
- Vote Rating
- 6
- Answers
- 57
-
20 Aug 2011 8:38 AM #3
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
-
22 Aug 2011 5:07 AM #4
Doing fine
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'] });Last edited by christocracy; 22 Aug 2011 at 6:05 AM. Reason: syntax error and wrong proxy type
/**
* @author Chris Scott
* @business www.transistorsoft.com
* @rate $120USD / hr; training $500USD / day / developer (5 dev min)
*
* @SenchaDevs http://senchadevs.com/developers/transistor-software
* @twitter http://twitter.com/#!/christocracy
* @github https://github.com/christocracy
*/
-
25 Aug 2011 12:53 AM #5
Also remove commas at the ends of association strings. It's just wrong.


Reply With Quote