Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-1611 in a recent build.
  1. #1
    Sencha User
    Join Date
    Jan 2012
    Posts
    36
    Vote Rating
    0
    benben is on a distinguished road

      0  

    Default [PR4] "hasMany" TypeError : reader undefined

    [PR4] "hasMany" TypeError : reader undefined


    Can't get a store to load if the model is a nested model using "hasMany".
    I get the following error as soon as i'm using it :
    TypeError: 'undefined' is not an object (evaluating 'reader.read')
    Here's the model :

    Ext.define('app.model.SearchResults', {
    extend: 'Ext.data.Model',
    config: {
    fields: [
    { name:'nbpages', type:'int' },
    { name:'nbads', type:'int' }
    ],
    hasMany: { associatedModel:'app.model.RealEstate', name:'realestates', associationKey:'data' }
    }
    });
    Note : i'm using "associatedModel" because the documentation for that class seems to indicate that this property is no longer called "model". I had the same error using "model".

    Here's the store :

    Ext.define('app.store.SearchResults', {
    extend:'Ext.data.Store',
    id:'SearchResults',
    config:{
    model:'app.model.SearchResults',
    autoLoad:true,
    proxy: {
    type:'ajax',
    url:'http://__thedomain__/search.pl',
    noCache:false,
    writer:{
    type:'json'
    },
    reader:{
    type:'json'
    },
    }
    },
    });
    And here's the store.load call :
    searchResultsStore.load({
    scope: this,
    params: searchParams.data,
    callback: this.onSearchResultsLoaded,
    });

  2. #2
    Sencha - Sencha Touch Dev Team Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    21
    Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough Jamie Avins is a jewel in the rough

      0  

    Default


    Thank you for the report.

    Sencha Inc

    Jamie Avins

    @jamieavins

  3. #3
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    9
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    I am not able to reproduce this error in the latest code branch. I'm running the following code snippet:

    Code:
            Ext.define('app.model.SearchResults', {
                extend: 'Ext.data.Model',
                config: {
                    fields: [
                        { name:'nbpages', type:'int' },
                        { name:'nbads', type:'int' }
                    ],
                    hasMany: {
                        associatedModel:'app.model.RealEstate',
                        name:'realestates',
                        associationKey:'data'
                    }
                }
            });
    
            Ext.define('app.store.SearchResults', {
                extend:'Ext.data.Store',
                id:'SearchResults',
                config:{
                    model:'app.model.SearchResults',
                    autoLoad:true,
                    proxy: {
                        type:'ajax',
                        url:'http://__thedomain__/search.pl',
                        noCache:false,
                        writer:{
                            type:'json'
                        },
                        reader:{
                            type:'json'
                        }
                    }
                }
            });
    
            Ext.setup({
                onReady: function() {
                    var store = new app.store.SearchResults();
                    
                    store.load({
                        scope: this,
                        params: {param1: 'test'},
                        callback: Ext.emptyFn,
                    });
                }
            });
    Could you verify if this code snippet generates the error for you? If it does, could you tell us if it happens after the response comes back or before the request even fires?

  4. #4
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    9
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    Ok, I'm pretty sure this has to happen after the response comes back. In this case I'm still not able to reproduce the error.

    Could you please provide a sample json response that comes back from your server side so I could investigate further?

    P.s. model is a shorthand for associatedModel when configuration an associated in a model definition and both should still work.

  5. #5
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    9
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    In the latest code branch the following code works:

    Code:
            Ext.define('app.model.RealEstate', {
                extend: 'Ext.data.Model',
                config: {
                    fields: [
                        {name: 'field1', type: 'int'}
                    ]
                }
            });
    
            Ext.define('app.model.SearchResults', {
                extend: 'Ext.data.Model',
                config: {
                    fields: [
                        {name:'nbpages', type:'int'},
                        {name:'nbads', type:'int'}
                    ],
                    hasMany: {
                        model:'app.model.RealEstate',
                        name:'realestates',
                        associationKey:'data'
                    }
                }
            });
    
            Ext.define('app.store.SearchResults', {
                extend: 'Ext.data.Store',
                id: 'SearchResults',
                config:{
                    model: 'app.model.SearchResults',
                    proxy: {
                        type: 'ajax',
                        url: 'test.json',
                        writer: {
                            type:'json'
                        },
                        reader: {
                            type:'json',
                            rootProperty: 'results'
                        }
                    }
                }
            });
    
            Ext.setup({
                onReady: function() {
                    var store = new app.store.SearchResults();
    
                    store.load({
                        scope: this,
                        params: {param1: 'test'},
                        callback: function(records) {
                            console.log(records, records[0].getData(true));
                        }
                    });
    
                }
            });
    I'm sending back the following json
    Code:
    {
        "success": true,
        "results": [{
            "nbpages": 5,
            "nbads": 5,
            "data": [
                {"field1": 1},
                {"field1": 2},
                {"field1": 3},
                {"field1": 4}
            ]
        }]
    }
    I'm closing this ticket for now. Please let us know if the problem still persists after the next release.

  6. #6
    Sencha User
    Join Date
    Jan 2012
    Posts
    36
    Vote Rating
    0
    benben is on a distinguished road

      0  

    Default Two stores (one local, the other remote), same model

    Two stores (one local, the other remote), same model


    I found where the problem came from, and i think this is a pretty heavy problem with sencha :

    We've got two stores using the same model. One is for local storage , the other for remote.

    Now the problem lies in that line (sencha-touch-all-debug-w-comments.js line 45009) of your handleInlineAssociationData function :

    Code:
    proxy = association.getAssociatedModel().getProxy();
    You are trying to find the proxy used for deserializing the object starting from the model, instead of using the proxy given by the store. In our case, that call returned the proxy for the wrong store (aka type:'localstorage' instead of type:'rest')

    Really don't know how to fix that...

  7. #7
    Sencha User
    Join Date
    Mar 2007
    Location
    Haarlem, Netherlands
    Posts
    1,243
    Vote Rating
    9
    TommyMaintz will become famous soon enough TommyMaintz will become famous soon enough

      0  

    Default


    Ok benben,

    That information already helps a lot hunting this bug down. Could you please give us a stripped down code example that shows the problem? Maybe you can modify the code I have posted before. It would be very useful for us.

  8. #8
    Sencha User
    Join Date
    Jan 2012
    Posts
    36
    Vote Rating
    0
    benben is on a distinguished road

      0  

    Default Code sample

    Code sample


    There you go (seems like defining the store isn't enough, you need to instanciate it) :
    Code:
      Ext.define('app.model.RealEstate', {
              extend: 'Ext.data.Model',
              config: {
                  fields: [
    
    
          		{name:'field1',type:'string'},
    
    
                ]
              }
          });
    
    
          Ext.define('app.model.SearchResults', {
              extend: 'Ext.data.Model',
              config: {
                  fields: [
              		{ name:'nbitems', type:'int' },
                  ],
              	hasMany: { associatedModel:'app.model.RealEstate', name:'realestates', associationKey:'data' }
          	}
          });
    
    
          Ext.define('app.store.FavoriteRealEstate', {
              extend  : 'Ext.data.Store',
              config:{
                  model   : 'app.model.RealEstate',
              	autoSync: false,
              	proxy: {
              	        type: 'localstorage',
              	        id  : 'FavoriteRealEstate'
              	},
              }
    
    
          });
    
    
          Ext.define('app.store.SearchResults', {
              extend: 'Ext.data.Store',
              id: 'SearchResults',
              config:{
                  model: 'app.model.SearchResults',
                  proxy: {
                      type: 'ajax',
                      url: 'search.pl',
                      writer: {
                          type:'json'
                      },
                      reader: {
                          type:'json',
                      }
                  }
              }
          });
          
    
    
          Ext.setup({
              onReady: function() {
                  var favorite = new app.store.FavoriteRealEstate();
                  
                  var store = new app.store.SearchResults();
    
    
                  store.load({
                      scope: this,
                      params: {theid: 390},
                      callback: function(records) {
                          console.log(records);
                      }
                  });
    
    
              }
          });

Thread Participants: 2

Tags for this Thread