Threaded View

  1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    44
    Answers
    3
    Vote Rating
    0
    celwell is on a distinguished road

      0  

    Default Answered: store loading issue with associated models

    Answered: store loading issue with associated models


    Hi,

    I have a model called Event that hasMany Comment records. I have a store of Events. When I load the Events store everything is great. But if I make a server-side change and then call Ext.getStore('Events').load() it only reloads the 'first level' of the Event model. I need it to reload the data of the associated models as well. The proxy is only on the Events store, by the way.

    In event details page/container:
    Code:
        this.getAt(0).getAt(0).setStore(record.photos());
        this.getAt(0).getAt(1).setStore(record.videos());
        this.getAt(6).getAt(1).setStore(record.comments());
    Events model:
    Code:
    Ext.define('WSI.model.Event', {
      extend: 'Ext.data.Model',
      requires: ['WSI.model.Photo', 'WSI.model.Video', 'WSI.model.Comment'],
      config: {
        fields: [
          {
            name: 'id',
            type: 'string'
          }, {
            name: 'title',
            type: 'string'
          }, {
            name: 'description',
            type: 'string'
          }, {
            name: 'category',
            type: 'string'
          }, {
            name: 'dateTimeStart',
            type: 'string'
          }, {
            name: 'dateTimeEnd',
            type: 'string'
          }, {
            name: 'locationName',
            type: 'string'
          }, {
            name: 'locationVicinity',
            type: 'string'
          }, {
            name: 'locationLat',
            type: 'string'
          }, {
            name: 'locationLng',
            type: 'string'
          }, {
            name: 'viewCount',
            type: 'number'
          }, {
            name: 'bookmarked_by_me',
            type: 'boolean',
            defaultValue: false
          }, {
            name: 'flagged_by_me',
            type: 'boolean',
            defaultValue: false
          }
        ],
        hasMany: [
          {
            associatedModel: 'WSI.model.Photo'
          }, {
            associatedModel: 'WSI.model.Video'
          }, {
            associatedModel: 'WSI.model.Comment'
          }
        ]
      }
    });
    Comment Model:
    Code:
    Ext.define('WSI.model.Comment', {
      extend: 'Ext.data.Model',
      config: {
        fields: [
          {
            name: 'id',
            type: 'string'
          }, {
            name: 'event_id',
            type: 'string'
          }, {
            name: 'text',
            type: 'string'
          }, {
            name: 'author',
            type: 'string'
          }, {
            name: 'viewCount',
            type: 'int'
          }, {
            name: 'flagCount',
            type: 'int'
          }, {
            name: 'mobileOrigin',
            type: 'int'
          }, {
            name: 'timestampCreated',
            type: 'string'
          }
        ]
      }
    });
    Events Store:
    Code:
    Ext.define('WSI.store.Events', {
      extend: 'Ext.data.Store',
      xtype: 'eventsstore',
      requires: ['WSI.model.Event'],
      config: {
        model: 'WSI.model.Event',
        pageSize: 15,
        autoLoad: false,
        proxy: {
          type: 'ajax',
          url: 'REMOVED',
          extraParams: {
            sort: 'today',
            category: 'all'
          },
          reader: {
            type: 'json',
            rootProperty: 'events'
          }
        }
      }
    });

    "Refresh All" function in main controller:
    Code:
    refreshAll: function() {
        return Ext.getStore('Events').load({
          scope: this,
          callback: function(records, operation, success) {
            if (success) {
              if (this.getEventDetailsContainer() != null) {
                return this.onViewEventCommand(null, this.getEventDetailsContainer().getEventRecord());
              }
            }
          }
        });
      }

  2. I don't know. Thanks for your help, but I just found out I can do this instead of associations. For the dataview of comments I just config this:


    PHP Code:
    xtype'eventcomments'         
    data: if record.get('comments').length 0 then record.get('comments') else null
    model
    'WSI.model.Comment' 
    and then it doesn't have the refreshing problem. I might come back to this when I have more time, so thanks a lot for your help, but this other way should work for now.

Thread Participants: 1

Tags for this Thread