Reputation: 11
I'm having a problem where an optional belongsTo relationship isn't properly pushed to store. In my Ember application I have a relationship between 2 models that is optional. For example imagine:
App.User = DS.Model.extend({
profile: DS.hasMany('profile', {'async': true})
});
App.Profile = DS.Model.extend({
user: DS.belongsTo('user', {'async': true})
});
where the "user" field in the "Profile" model can be empty. When it is empty, the serializer should return
....
relationships: {
user: null
}
...
in the normalized payload, at least if I have interpreted the JSON-API standard (JSON-API resource linkage) correctly. The problem is that this doesn't seem to be pushed to the store. I can reproduce this problem by
After these steps the "user" field on the "Profile" record still maintains its faulty, non-null value.
Is this expected behaviour or a bug? If this is expected behaviour, how should I track these changes in order to maintain data integrity?
Upvotes: 1
Views: 240
Reputation: 11
After a second look at the JSON-API it seems I have interpreted it wrong. The normalized payload should instead be
...
relationships: {
user: {
data: null
}
}
...
which solved it for me.
Upvotes: 0