Correct way of showing model metadata in template


I’m using ember-cli (0.2.3) and I’ve to show a list of models plus additional metadata informations:

This is my route:

import Ember from 'ember'
import AuthenticatedRouteMixin from 'simple-auth/mixins/authenticated-route-mixin'

export default Ember.Route.extend AuthenticatedRouteMixin,
  model: ->
    @store.findQuery 'dashboard', scope: 'personal'
  renderTemplate: ->
    @render 'dashboards.index'

this is my current template (emblem):

    link-to 'dashboards.personal'
      %span Personal
      .counter = meta.counters.personal

... etc

and my current controller:

import Ember from 'ember'

export default Ember.Controller.extend
  meta: Ember.computed 'model.isLoaded', ->
    @store.metadataFor 'dashboard'

this works fine on first load, but navigating from another page generates this exception:

Error while processing route: dashboards.published Cannot convert object to primitive value TypeError: Cannot convert object to primitive value
    at SETTER_FUNCTION [as counters] (http://localhost:4200/assets/vendor.js:25664:98)
    at Object.merge (http://localhost:4200/assets/vendor.js:24217:22)
    at ember$data$lib$system$store$$Service.extend.setMetadataFor (http://localhost:4200/assets/vendor.js:72915:15)
    at ember$data$lib$system$serializer$$default.extend.extractMeta (http://localhost:4200/assets/vendor.js:65891:17)
    at ember$data$lib$system$serializer$$default.extend.extract (http://localhost:4200/assets/vendor.js:65634:14)
    at http://localhost:4200/assets/vendor.js:67404:32
    at (http://localhost:4200/assets/vendor.js:10766:27)
    at ember$data$lib$system$store$$Service.extend._adapterRun (http://localhost:4200/assets/vendor.js:73545:33)
    at http://localhost:4200/assets/vendor.js:67403:15
    at tryCatch (http://localhost:4200/assets/vendor.js:57486:16)

basically setMetadataFor tries to run Object.merge and it throws an error since it uses = and not Ember.set()

As a workaround using Ember.copy @store.metadataFor('dashboard') works fine but I don’t think it’s the best solution.

What’s the correct way to access metadata from template?

PS: I’ve tried to just use model.meta.counters.personal but it doesn’t work.


I am also facing same issue, do you have solution for this? Ember.copy did not work for me.


I’ve left it as:

meta: Ember.computed 'model.@each', ->
    Ember.copy @store.metadataFor('dashboard')

and it’s working, however I don’t like the Ember.copy approach, but since nobody replied, I don’t know if there’s a better way


I have the same Problem, but Ember.copy works. thanks a lot!

But this cant be right, is this a bug or something?


FWIW ran into same issue w/ returning meta from a cp. Don’t mind the copy and it worked fine :thumbsup: Thanks for sharing!