@ChrizzDF wrote:
Hi there,
I would be really happy if someone could fix this problem...
I already searched the Mirage issues section, google, here on ember discuss, etc.Everything is working fine as soon as I define a relationship on a Mirage Model the console throws the following error:
All I want to do is having a relationship between 2 models:
Competition
andFixture
(Football related).My related files are looking like that:
Models
// app/models/competition.js import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import { hasMany } from 'ember-data/relationships'; export default Model.extend({ caption: attr('string'), league: attr('string'), year: attr('number'), currentMatchday: attr('number'), numberOfMatchdays: attr('number'), numberOfTeams: attr('number'), numberOfGames: attr('number'), lastUpdated: attr('date'), fixtures: hasMany('fixture'), });
// app/models/fixture.js import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import { belongsTo } from 'ember-data/relationships'; export default Model.extend({ date: attr('date'), status: attr('string'), matchday: attr('number'), homeTeamName: attr('string'), awayTeamName: attr('string'), competition: belongsTo('competition'), });
// mirage/models/competition.js import { Model, hasMany } from 'ember-cli-mirage'; export default Model.extend({ fixtures: hasMany(), });
// mirage/models/competition.js import { Model, belongsTo } from 'ember-cli-mirage'; export default Model.extend({ competition: belongsTo(), });
Fixtures
// mirage/fixtures/competitions.js export default [ { id: 1, caption: 'European Championships France 2016', league: 'EC', year: '2016', currentMatchday: 3, numberOfMatchdays: 7, numberOfTeams: 24, numberOfGames: 38, lastUpdated: '2016-06-22T04:34:39Z', fixtures: [1, 2], }, ];
// mirage/fixtures/fixtures.js export default [ { id: 1, date: '2016-06-10T19:00:00Z', status: 'FINISHED', matchday: 1, homeTeamName: 'France', awayTeamName: 'Romania', competition: 1, }, { id: 2, date: '2016-06-10T19:00:00Z', status: 'FINISHED', matchday: 1, homeTeamName: 'Italy', awayTeamName: 'Germany', competition: 1, }, ];
Adapter
// app/adapters/application.js import DS from 'ember-data'; import ENV from '../config/environment'; export default DS.RESTAdapter.extend({ host: ENV.dataInterface, namespace: ENV.namespace, }); // host = 'http://localhost:4200' // namespace = 'api'
Serializers
// app/serializers/application.js import RESTSerializer from 'ember-data/serializers/rest'; export default RESTSerializer.extend({ });
// mirage/serializers/application.js import { RestSerializer } from 'ember-cli-mirage'; export default RestSerializer.extend({ });
If I comment out the fixtures hasMany relationship on the Mirage model, I'm not getting the error anymore, but of course I need that relationship.
I'm using the (currently) latest
ember-cli-mirage
version which is0.2.1
.If you need further information, please let me know and I'll provide you!
Thanks in advance!!! =)
Posts: 1
Participants: 1