I'm trying to get data from a server and set it to Ember's DS.Model (by ember's magic). But records are created with no data.
I have got a model models/product.js:
const { Model } = DS;
export default Model.extend({
name: DS.attr(),
price: DS.attr()
});
In routes/product.js I request all products:
model() {
return this.store.findAll('product');
}
The server returns data: https://gyazo.com/ba38b756f334bc22d07fe18ccfddda34
I expect ember to create 3 records with data from the server. But actually, it creates this https://gyazo.com/a9a7b77d838ec33b05e5f81ef8304cdb
What is wrong? I guess I shouldn't specify any adapters and serializers to get default Ember behavior.
Your API does not follow JSON:API specification but that one is used by Ember Data as default. If you don't follow that convention you need to alter applications serializer and adapter. Let me quote Ember docs about it:
Ember Data flexibility
Thanks to its use of the adapter pattern, Ember Data can be configured to work with many different kinds of backends. There is an entire ecosystem of adapters and several built-in adapters that allow your Ember app to talk to different types of servers.
By default, Ember Data is designed to work out of the box with JSON:API. JSON:API is a formal specification for building conventional, robust, and performant APIs that allow clients and servers to communicate model data.
JSON:API standardizes how JavaScript applications talk to servers, so you decrease the coupling between your frontend and backend, and have more freedom to change pieces of your stack.
If you need to integrate your Ember.js app with a server that does not have an adapter available (for example, you hand-rolled an API server that does not adhere to any JSON specification), Ember Data is designed to be configurable to work with whatever data your server returns.
Source: https://guides.emberjs.com/release/models/#toc_ember-data-flexibility
I'm not sure if it was a question or a normative statement, but actually you must specify adapters and serializers if your API is not a JSON:API.