0
votes

I have problem defining the relationship between my models in order to get cascading property. I would like to MapLineString to be deleted when Trail is deleted or Draw is deleted. But I DO NOT want Trail to be deleted when MapDraw or MapLineString gets deleted.

Relationship between the models is :

Trail can have one Trailer, one Team and one mapDraw

MapDraw can have many MapLineString

MapLineString can belongs to Trail AND/OR MapDraw

Trail = DS.Model.extend({
  Trailer: DS.belongsTo('mapLinestring', {async: true, inverse: 'trail'}),
  Team: DS.belongsTo('mapLinestring', {async: true, inverse: 'trail'}),
  mapDraw: DS.belongsTo('mapDraw', {async: true}),
});

MapDraw = DS.Model.extend({
  lineStrings: DS.hasMany('mapLinestring', {async: true}),
  trail: DS.belongsTo('mtgTrail')
});

MapLineString = DS.Model.extend({
  trail: DS.belongsTo('mtgTrail'),
  mapDraw: DS.belongsTo('mapDraw'),
});

Assertion Failed: You defined the 'trail' relationship on mantrailling@model:map-linestring:, but you defined the inverse relationships of type mantrailling@model:mtg-trail: multiple times. Look at http://emberjs.com/guides/models/defining-models/#toc_explicit-inverses for how to explicitly specify inverses

2
your usage of a's, b's, and c's to define attrs and models doesnt make for easy comprehension of the problem.Craicerjack

2 Answers

0
votes

Looking at what youve written at the beginning of the post it sounds like
A should be:

export default DS.Model.extend({
  bees: DS.hasMany('B', {async: true, inverse: 'abees'}),
  cees: DS.hasMany('C', {async: true}),  //doesnt need an inverse as you are getting all the ones that belong to A
});    

B should be:

export default DS.Model.extend({
  cees: DS.hasMany('C', {async: true, inverse: 'bcees'}),
  abees: DS.belongsTo('A')
});    

and then in C you have two model properties called the same thing

export default DS.Model.extend({
  acees: DS.belongsTo('A'),
  bcess: DS.belongsTo('B')
});    

Your naming conventions also make it quite confusing. Why not just name the attrs of the models something thats relevant to what they represent?

0
votes

Ok, I found out what the problem was. I have been using Localstorage adapter, which does not work with {async: true}. The records were not persisted on the parent side.