dimanche 28 juin 2015

Ember Data hasMany relationship empty result

I'm using ember-cli 0.2.7 and I'm not sure why but it seems that I can't retrieve the tags for my newsletter model.

newsletter.js

import DS from 'ember-data';

export default DS.Model.extend({
  title: DS.attr('string'),
  tags: DS.hasMany('tag')
});

tag.js

import DS from 'ember-data';

export default DS.Model.extend({
  newsletter: DS.belongsTo('newsletter', {async: true}),
  name: DS.attr('string')
});

API response (rails backend using ActiveModelSerializer):

{
  "newsletters": [
    {
      "id": 1,
      "title": "Panel Weekly",
      "tag_ids": [
        1
      ]
    },
    {...}
  ],
  "tags": [
    {
      "id": 1,
      "name": "arts"
    },
    {...}
}

I don't know how to retrieve the list of tags for a newsletter. I tried this using the ember inspector and the console ($E containing the first newsletter):

>$E.get('tags.length')
0
>$E.get('tags')
Class {canonicalState: Array[0], store: Class, relationship: ember$data$lib$system$relationships$state$has$many$$ManyRelationship, record: Class, currentState: Array[0]…}
>$E.get('title')
"Panel Weekly"




Aucun commentaire:

Enregistrer un commentaire