1. #1
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    102
    Vote Rating
    1
    anarchos78 is on a distinguished road

      0  

    Default Unanswered: Ext associations

    Unanswered: Ext associations


    Hello,
    I have a question: The “associations” feature (HasMany-belongsTo) of ExtJs library is applicable only in nested JSON data? Is it doable to define two different stores with two different data retrieving “urls” (and two different models with the association definition?) and the “hasMany” works? Or, I have to define only one store (with one data retrieving “url” and a JSON output that is nested and reflects the data associations of the database) and then with the help of models “format” the data in a way that Ext can consume?
    If the second case it is true, how someone could handle large volume data (let’s say a blog: users=>blog-post=>blog-reply) using the Ext “association” feature?
    Sorry for my abstract writing style,
    Tom,
    Greece

  2. #2
    Sencha User
    Join Date
    Feb 2010
    Posts
    125
    Answers
    7
    Vote Rating
    3
    börn is on a distinguished road

      0  

    Default


    erm.... don't understand - can you ask again in a more verbatim style?

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Location
    Sweden
    Posts
    36
    Answers
    10
    Vote Rating
    0
    JambaFun is on a distinguished road

      0  

    Default


    No problem understanding. Your best bet is to load associated data in a second call. You get stores automatically created on your primary model and these could be loaded separately.

  4. #4
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    102
    Vote Rating
    1
    anarchos78 is on a distinguished road

      0  

    Default


    Let's give an example:
    The post model
    Code:
    
    Ext.define('app.model.Post', {   extend:'Ext.data.Model',   fields:[     {name:'id', type:'int'},      {name:'title'},     {name:'body'}   ],   proxy:{     type:'ajax',     url:'data/posts.json',     reader:{       type:'json',       root:'posts'     }   },   hasMany:[     {       name:'categories',       model:'app.model.Category'     }   ] })
    The Category model

    Code:
    Ext.define('app.model.Category', {   extend:'Ext.data.Model',   fields:[     {name:'id', type:'int'},     {name:'name', type:'string'}   ],   proxy:{     type:'ajax',     url:'data/categories.json',     reader:{       type:'json',       root:'categories'     }   } });

    The application:
    Code:
    
    
    Ext.Loader.setConfig({     enabled: true });  Ext.application({     name: 'app',     autoCreateViewport:false,     enableQuickTips:false,     requires:[       'app.model.Post',       'app.model.Category'     ],      launch: function() {       app.model.Post.load(1, {  success: function(record, op){    console.log(record.categories())  }       })     } });
    The above code block is not working. In my opinion it doesn't work because in the second model i am using a second url to "pull" the data. I think extjs needs a format like:
    Code:
    {   "success":true,   "posts":[     {       "id":1,       "title":"hi",       "body":"there",       "categories":[  {    "id":1,    "name":"hardware"  },  {    "id":3,    "name":"software"  }       ]     },     {       "id":2,       "title":"so",       "body":"long",       "categories":[  {    "id":1,    "name":"hardware"  },  {    "id":2,    "name":""  }       ]     }   ] }
    The working code is:
    The post model
    Code:
    
    Ext.define('app.model.Post', {   extend:'Ext.data.Model',   fields:[     {name:'id', type:'int'},      {name:'title'},     {name:'body'}   ],   proxy:{     type:'ajax',     url:'data/posts.json',     reader:{       type:'json',       root:'posts'     }   },   hasMany:[     {       name:'categories',       model:'app.model.Category'     }   ] })
    The Category model

    Code:
    Ext.define('app.model.Category', {   extend:'Ext.data.Model',   fields:[     {name:'id', type:'int'},     {name:'name', type:'string'}   ] });

    The application:
    Code:
    
    
    Ext.Loader.setConfig({     enabled: true });  Ext.application({     name: 'app',     autoCreateViewport:false,     enableQuickTips:false,     requires:[       'app.model.Post',       'app.model.Category'     ],      launch: function() {       app.model.Post.load(1, {  success: function(record, op){    console.log(record.categories())  }       })     } });
    and the posts.json file:

    Code:
    {   "success":true,   "posts":[     {       "id":1,       "title":"hi",       "body":"there",       "categories":[  {    "id":1,    "name":"hardware"  },  {    "id":3,    "name":"software"  }       ]     },     {       "id":2,       "title":"so",       "body":"long",       "categories":[  {    "id":1,    "name":"hardware"  },  {    "id":2,    "name":""  }       ]     }   ] }
    By using the second (working) code block, I have to pull the whole database in one request! Are there any ideas in how to load what it is really needed?

    Thanks

  5. #5
    Ext JS Premium Member
    Join Date
    Oct 2009
    Posts
    29
    Vote Rating
    3
    iesdeveloper is on a distinguished road

      0  

    Default


    After retrieving the desired Post record, you need to call .load() again on the record's related categories() store:

    PHP Code:
    app.model.Post.load(1, {
      
    success: function(recordop){    
        
    record.categories().load({
           
    successconsole.log(record.categories()) 
        }); 
      }       
    }); 

Thread Participants: 3

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi