1. #1
    Sencha User
    Join Date
    Jan 2011
    Posts
    2
    Vote Rating
    0
    temp05 is on a distinguished road

      0  

    Question 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:
    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

  2. #2
    Sencha User tobiu's Avatar
    Join Date
    May 2007
    Location
    Munich (Germany)
    Posts
    2,684
    Answers
    130
    Vote Rating
    112
    tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all tobiu is a name known to all

      0  
    Best regards
    Tobias Uhlig
    __________

    S-CIRCLES Social Network Engine

  3. #3
    Sencha User
    Join Date
    Jan 2011
    Posts
    2
    Vote Rating
    0
    temp05 is on a distinguished road

      0  

    Default


    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

  4. #4
    Ext JS Premium Member christocracy's Avatar
    Join Date
    Oct 2006
    Location
    Montreal
    Posts
    381
    Vote Rating
    0
    christocracy is on a distinguished road

      0  

    Default 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 $150USD / 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
    */

  5. #5
    Sencha User
    Join Date
    Apr 2011
    Posts
    8
    Vote Rating
    0
    Berzzzebub is on a distinguished road

      0  

    Default


    Also remove commas at the ends of association strings. It's just wrong.