1
votes

Version: Ember 2.11

I am trying to use Ember data model to load the data from REST API but it is failing with error message as

           ember.debug.js:17634 Assertion Failed: You need to pass a model 
           name to the store's modelFor method
           Error
           at assert (http://localhost:4200/assets/vendor.js:16249:13)
           at Object.assert 
            (http://localhost:4200/assets/vendor.js:27921:34)
           at assert (http://localhost:4200/assets/vendor.js:76154:37)
           at Class.modelFor 
           (http://localhost:4200/assets/vendor.js:86032:41)
            at Class._internalModelForId 
            (http://localhost:4200/assets/vendor.js:85168:29)

Here is my code:

serializer/sfresult.js

              import DS from 'ember-data';
                 export default DS.RESTSerializer.extend({

                });

serializer/sfresults.js

              import DS from 'ember-data';
                 export default DS.RESTSerializer.extend({

                });

models/sfresult.js

              import DS from 'ember-data';
             export default  DS.Model.extend({
              sfresults: DS.hasMany('sfresults', { async: false }),
              message: DS.attr('string')

        });

models/sfresults.js

               import DS from 'ember-data';

                export default  DS.Model.extend({

                title: DS.attr('string'),
                 description: DS.attr('string'),
                caseNumber: DS.attr('string'),
                lastModifiedDate: DS.attr('string'),
                type: DS.attr('string'),
                url: DS.attr('string'),
                searchText: DS.attr('string'),
                messageId: DS.attr('string')
          });

controller code:

                 let sfdata = this.store.query('sfresult',{ 'searchText': inputSearchText, 'searchType' : 'SF' } );

JSON Response:

         { 
         "sfresult":{  
         "message":"SUCCESS",
           "sfresults":[  
               {  
               "viewScore":"100.0",
                "caseNumber":"000005462",
                "id":"1d725883-15f2-4f18-927c-b14455440458",
                "url":"url1",
                "title":"title",
                 "description":"",
                 "lastModifiedDate":"12/29/16"
                },
               {  
                  "caseNumber":"00007082",
                   "status":"Closed",
                  "id":"b79c0397-f544-45f0-8b91-e2bb7a386ebf",
                  "url":"ur2",
                   "title":"title1?",
                   "description":"",
                   "messageId":"500E000000DPA33IAH",
                   "lastModifiedDate":"08/16/16"
                }

              ]
             "id":"2b238d70-01ce-4604-913f-29d4c5eeba60"
         }

      }

i wanted to get sfresult and iterate it to display it in UI. In Ember tab I could see data is getting loaded to sfresult and don't see any thing in sfresults object. I have tried many combinations but could not able to make it working. Can some body please help on this.

1
@ebrahim-pasbani do you have any idea on this?Amarnathreddy Pappu

1 Answers

0
votes

If you haven't fixed this yet, try to update the serializer/sfresult.js like this:

import DS from 'ember-data';

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
    attrs: {
        sfresults: { serialize: 'ids', deserialize: 'records' }
    }
});