I’m attempting to get a simple example working using Ember Data.
Here is my REST adapter:
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host: 'http://localhost:3000'
});
After my page loads I click on my Ember tab in Chrome’s developer tools and click on ‘$E’ under controller. I then type ‘$E.store.findAll(‘property’);’ and get the following in the console:
WARNING: Encountered “0” in payload, but no model was found for model
name “0” (resolved model name using
web-content@serializer:application:.modelNameFromPayloadKey(“0”))
ember.debug.js:5207 WARNING: Encountered “1” in payload, but no model
was found for model name “1” (resolved model name using
web-content@serializer:application:.modelNameFromPayloadKey(“1”))
ember.debug.js:5207 WARNING: Encountered “2” in payload, but no model
was found for model name “2” (resolved model name using
web-content@serializer:application:.modelNameFromPayloadKey(“2”))
ember.debug.js:5207 WARNING: Encountered “3” in payload, but no model
was found for model name “3” (resolved model name using
web-content@serializer:application:.modelNameFromPayloadKey(“3”))
ember.debug.js:5207 WARNING: Encountered “4” in payload, but no model
was found for model name “4” (resolved model name using
web-content@serializer:application:.modelNameFromPayloadKey(“4”))
ember.debug.js:5207 WARNING: Encountered “5” in payload, but no model
was found for model name “5” (resolved model name using
web-content@serializer:application:.modelNameFromPayloadKey(“5”))
ember.debug.js:5207 WARNING: Encountered “6” in payload, but no model
was found for model name “6” (resolved model name using
web-content@serializer:application:.modelNameFromPayloadKey(“6”))
ember.debug.js:5207 WARNING: Encountered “7” in payload, but no model
was found for model name “7” (resolved model name using
web-content@serializer:application:.modelNameFromPayloadKey(“7”))
Error: Assertion Failed: You must include an ‘id’ for undefined in an object passed to ‘push’
at new Error (native)
at Error.EmberError (http://192.168.11.12:4200/assets/vendor.js:25605:21)
at Object._emberMetalCore.default.assert (http://192.168.11.12:4200/assets/vendor.js:15745:13)
at ember$data$lib$system$store$$Service.extend._pushInternalModel (http://192.168.11.12:4200/assets/vendor.js:72947:15)
at ember$data$lib$system$store$$Service.extend.push (http://192.168.11.12:4200/assets/vendor.js:72933:34)
at http://192.168.11.12:4200/assets/vendor.js:67921:17
at Object.Backburner.run (http://192.168.11.12:4200/assets/vendor.js:10838:25)
at ember$data$lib$system$store$$Service.extend._adapterRun (http://192.168.11.12:4200/assets/vendor.js:73169:33)
at http://192.168.11.12:4200/assets/vendor.js:67918:15
at tryCatch (http://192.168.11.12:4200/assets/vendor.js:60951:14)
This can be handled in a serializer, should be quite straightforward for this particular case. But it’ll get more involved if you need model relationships, etc.
Depends on your needs I guess. It works well for simple scenarios and beyond. I have built applications without ED and they work just fine. Using ED makes sense when you have plenty of different CRUD forms and relationships between models. The project I’m working on at the moment is a perfect use case for ED and it saved me a ton of precious time
Square, you definitely need a serializer. It’s easy for your example.
There are several options, you can extend the normalize* functions in a RESTSerializer or even JSONAPISerializer. With JSON API, that array should be normalized to something like: