Undefined properties with multiple belongsTo for the same type


So I have models with multiple belongsTo for the same type.

My paylod is something like this:

//paylod related to model note
  "id": "191",
  "notes": [
      "id": "23",
      "id_main_note": "191",
      "id_related_note": "201"
  "number": "2222NE222222"

And my Ember models are something like this:

export default DS.Model.extend( {
  numero: DS.attr('string'),
  notes: DS.hasMany('related-note')

export default DS.Model.extend( {
  mainNote:  DS.belongsTo('note'),
  relatedNote:  DS.belongsTo('note')

And then I get this message:

"Assertion Failed: You defined the 'notasEmpenhoRelacionadas' relationship on (unknown mixin), but multiple possible inverse relationships of type (unknown mixin) were found on (unknown mixin). Look at https://guides.emberjs.com/current/models/relationships/#toc_explicit-inverses for how to explicitly specify inverses"

So I’ve changed the related-note model to this:

export default DS.Model.extend({
  mainNote: DS.belongsTo('note', {inverse: 'notes'}),
  relatedNote: DS.belongsTo('note')

And the I get the correct mainNote value but the relatedNote value is undefined. How can I get the correct values to both belongsTo attributes that have the same type?

Thanks in advance!


(I’m not at a computer to write out a longer answer)

I’d recommend reading the docs on reflexive relationships https://guides.emberjs.com/v2.7.0/models/relationships/#toc_reflexive-relations

Based on what I see, I think you’ll want a single note model that could have a main/parent note or a related/child note.