Ember.js: How to access JSON API metadata from a call to store.findRecord

I'm currently trying to figure out how to access metadata when using the store.findRecord() call.

The guides ( http://guides.emberjs.com/v2.1.0/models/handling-metadata/ ) say that metadata can be accessed by following these steps:

 store.query('post').then((result) => { let meta = result.get('meta'); }) 

I was hoping this would work when using findRecord as well

 store.findRecord('book', params.id, {adapterOptions: {query: params}}).then((result) => { let meta = result.get('meta'); }) 

However, this always returns undefined for the meta property. I assume that metadata is not set when using findRecord . I am returning a valid JSON API with the top level meta property as follows:

 { "meta": { "page": { "number": 1, "size": 100, "total": 20 }, "data":[ // data here ] } } 

Is there a way to access the metadata returned by the server using findRecord () and JSONAPISerializer and JSONAPIAdapters?

Thanks!

I use the following versions:

 Ember : 2.1.0 Ember Data : 2.1.0 jQuery : 1.11.3 
+5
source share
1 answer

metadata is not supported on a per-record basis, you can rely on its availability if you use store.query() or when receiving relationships. Citation:

At present, Ember Data only understands the top-level meta object in terms of queries and relationships (via related links).

See the following github thread for more information.

+2
source

Source: https://habr.com/ru/post/1235804/


All Articles