Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4870

Optional relationship?

$
0
0

I’m using Ember Data 4.1 and Ember 4.7.

I have tables named person and photo. What I want is for this relationship to be optional. A person may have many photos or none at all. A photo may be owned by a person or have no owner.

I thought I could use hasMany and belongsTo in both model scripts by setting {inverse: null} like:

My person model has this: @hasMany(“photo”, { inverse: null }) photo;

My photo model has this: @belongsTo(“person”, { inverse: null }) person_id;

This works fine until I try to save a photo with the photo.person_id set to null. But while the photo record is saved with photo.person_id = null, Ember Data tries to find a person with an id of 0. That results in this error:

Error: Assertion Failed: You made a ‘findRecord’ request for a ‘person’ with id ‘0’, but the adapter’s response did not have any data.

My API returns false when a single record is not found. Is there a way to do what I’m trying to do with Ember Data?

6 posts - 2 participants

Read full topic


Viewing all articles
Browse latest Browse all 4870

Trending Articles