I tried to implement the meta data myself. The only solution I found was to write a custom serializer that writes the meta information into a global variable accessible by the app.
We are using this currently on an ember 1.0-pre4 app and it’s working as expected. I think a better solution would be to work with a pagination controller that gets passed the meta information instead of relying on an object in the app namespace but I haven’t had the time to refactor my current solution yet.
As I pointed out I am aware that the global variable approach is not a good solution. The interesting part is to extract the meta information and this can be done with a custom serializer.
It works. @LevelbossMike the code below uses Ember’s default meta data getter with each model on its own. So you don’t need to use a custom method or override serializer.
@seif Did you get this to work with computed properties? I am able to get the meta information into the store and to access it via the typeMapsFor method of the store on the console. But I am not able to bind on the metadata for a model.
Does anybody know how to access the metadata from a controller?
SomeController = Ember.ArrayController.extend
pagination: ( ->
# won't work! taken from https://github.com/emberjs/data/pull/815
this.get('content.store.typeMaps.metadata') # => undefined
).property('content.store.typeMaps.@each.metadata')
As I have read in the Ember-Data source it seems to be impossible to bind to the typemaps array of the store. So I am pretty clueless how this should work.
I think it would be nice to have a property on the ResultArray for the meta information but his also does not seem to work as one might expect:
I guess several people are using the undocumented meta information hook in ember data but I wasn’t able to find any example apps. Did anybody of you get this to work in a nice way?
I want this to be in the controller. I tried to access the metadata from the model/content property of the controller as suggested in the pull request you referenced.
Thx! Unfortunately this won’t work when I want to build a pagination based on metadata information passed in a serializer because I need to observe the metadata property to use it in a pagination controller / template.
This is basically what I want to do:
App.SomethingRoute = Ember.Route.extend
model: ->
App.Something.find()
App.SomethingController = Ember.ArrayController.extend
pagination: ( ->
this.get('model.metadata.pagination') # => of course this won't work
).property('model.isLoaded')
I don’t think I am the only one who needs pagination in his/her apps. Accessing the metadata is the last missing piece in the puzzle.
I answered my original question on stackoverflow myself. The described way works with the typeMaps property of the store. If anybody knows better please comment on the SO issue.
Just merged a solution for meta into master. Should land in the next beta. This allows you to bind directly to recordArray.meta However, there needs to be discussion around whether it will make it into Ember Data 1.0 and in what form. See the pull request.
In my opinion we should be able to bind on the meta object so we can display this information in templates e.g. page, total count, page count, search facets etc.