1. With the records returned from the store, you may need to work with some meta data. Metadata is a data that accompanies a particular model or Tyep , not a record.
2. Paging is a common example of using metadata. Imagine a blog that has more posts than you can show at one time. You might find this:
this. Store.query ("Post", { ten, 0});
3. To get the data from different pages, you can simply change the offset to 10. So far, everything is fine. But if you know how many pages of data you have? Your server needs to return the total number of records as part of the metadata.
4. Each serialization will expect to return different meta data. For example, the JSON deserializer for Ember data looks for a meta key:
{ "post": { "id": 1, "title": "Progressive enhancement is Dead", "Comments": ["1", "2"], "links": { "user": "/people/tomdale" }, // ... }, " Meta ": { " total ": +} }
5. Regardless of the serializer used, this metadata is extracted from the response. You can read it by using . Get (' meta ') .
6. This can be done in the result of calling Store.query () :
Store.query (' Post '). Then (Result) = { = result.get (' meta ');})
7. In the belongsto relationship:
Let post = Store.peekrecord (' Post ', 1);p ost.get (' author '). Then ((author) = { = Author.get (' (Meta ');});
Or in a hasmany relationship:
Let post = Store.peekrecord (' Post ', 1);p ost.get (' comments '). Then ((comments) = { = Comments.get (' meta ');});
8. After reading it,meta.total can be used to calculate how many pages there are.
7.10 Models--handling Metadata (processing metadata)