Quantcast
Viewing all articles
Browse latest Browse all 4827

Undefined properties with multiple belongsTo for the same type

@kamillacrozara wrote:

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:

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


//related-note.js
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!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4827

Trending Articles