1. #1
    Sencha User
    Join Date
    Dec 2010
    Posts
    81
    Vote Rating
    0
    babar.sajjad is on a distinguished road

      0  

    Question Loading Multiple Models by Association using Store

    Loading Multiple Models by Association using Store


    Hi,
    I have two tables User and Meal. And these models are associated with each other :
    Code:
    Ext.regModel('User', {
         fields:[ 'id','uuid', ‘name’ ],
    	associations: [
    	        {type: 'hasMany', model: 'Meal', name: 'Meal', associationKey: 'Meal'}
        ]
    });
    Ext.regModel('Meal', {
        fields:[
                'id','name'
            ]
    });
    I m loading these Models in store like this:
    Code:
    var store = new Ext.data.Store({
    	model: 'User',
    	storeId: 'UserStore',
    	proxy: {
    		type: 'ajax',
    		url : 'http://myurl',
    		reader: {
    			type: 'xml',
    			root: 'response',
    			record: 'User'
    		},
    		filters: [],
    	}
    });
    The response is in XML format is.
    Code:
    <?xml version="1.0" encoding="utf-8"?>
    <nutritions_response>
      <data>
        <response>
          <item>
            <User>
              <id>1192</id>
              <uuid>4d36ea13-47d0-4ecd-94dc-082832e59055</uuid>
              <name>test</name>
              <Meal>
                <item>
    		<id>6353</id>
    		<name>Breakfast</name>
    	    </item>
    	    <item>
                  <id>6354</id>
                  <name>Lunch</name>
                </item>
     	  </Meal>
            </User>
          </item>
        </response>
      </data>
    </nutritions_response>
    And when I load the store it only loads User data instead of loading both User and Meal data. I follow the documentation but did not get required results. Any help is appreciated. Thanks in advance.

  2. #2
    Sencha User
    Join Date
    Dec 2010
    Posts
    81
    Vote Rating
    0
    babar.sajjad is on a distinguished road

      0  

    Default


    any body in the forum who can help me ?

  3. #3

  4. #4
    Sencha Premium Member couetbis's Avatar
    Join Date
    Jan 2008
    Location
    Nantes - France
    Posts
    105
    Vote Rating
    1
    couetbis is on a distinguished road

      0  

    Default


    Try with adding a belongsTo association

    Code:
    Ext.regModel('User', {
         fields:[ 'id','uuid', ‘name’ ],
    	associations: [
    	        {type: 'hasMany', model: 'Meal', name: 'meals'}
        ]
    });
    Ext.regModel('Meal', {
        fields:[
                'id','name'
            ],
        associations: [
    	        {type: 'belongsTo', model: 'User'}
        ]
    });

Similar Threads

  1. Some Models one Store?
    By bsander in forum Sencha Touch 1.x: Discussion
    Replies: 1
    Last Post: 6 Aug 2010, 12:06 AM
  2. RpcProxy how to load multiple models ...super torture bug ?
    By gauravpd in forum Ext GWT: Discussion
    Replies: 2
    Last Post: 28 Apr 2010, 3:20 AM
  3. Loading data store from multiple sources for tabbed form
    By rbraddy in forum Ext 3.x: Help & Discussion
    Replies: 7
    Last Post: 17 Oct 2009, 1:27 PM
  4. HELP!!!!!!! have multiple selection models in a grid????
    By abhatia in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 25 Jul 2008, 9:51 AM
  5. Multiple store loading problem
    By deanoj in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 28 Apr 2008, 2:14 AM

Thread Participants: 2

Tags for this Thread