samedi 25 juin 2016

Ember + Mirage and relationships

i'm working with Ember 2.6 and currently using Mirage for a client hosted static database.

I started using fixtures du provide the sample data, but I cannot make the relationships work.

I have 2 entities : island and spot, with a Many to One relationship

//mirage/models/spot.js
import { Model, belongsTo } from 'ember-cli-mirage';   
export default Model.extend({
  island: belongsTo()
});

and

//mirage/models/island.js
import { Model, hasMany } from 'ember-cli-mirage';
export default Model.extend({
  spots: hasMany()
});

and my fixture data

//mirage/fixture/spots.js
export default [
  {id: '1', name: 'test spot', island_id: [1]},
}

and

//mirage/fixture/islands.js
export default [
  {id: '1', name: 'Island 1 Name', permit: null, spot_ids: [1]},
}

my config.js is just a simple getAll

  this.get('/islands', function(schema, request){
    return schema.islands.all();
  });

But when I call it, I got my islands, but the relationships are missing.

Using the default json api adapter.

How to make Mirage return json data with the given relationships ? I tried to set the relation in both sides and 2 at the same time and neither provides the child entity.

Here is a link of my project on github : http://ift.tt/290uv5j




Aucun commentaire:

Enregistrer un commentaire