-
-
Notifications
You must be signed in to change notification settings - Fork 861
Description
Bug Report
Current Behavior
A javascript error is thrown when using Model.save() to save a null value on a hasOne relationship.
Steps to Reproduce
Run:
app.store.all('users')[0].save({relationships: {customHasOne: null}})
(it doesn't matter if the relationship is registered on the model or not since the code never checks if it exists)
See error:
Uncaught TypeError: t is null
getIdentifier http://beta16.flarum.localhost/assets/forum-31c35670.js:1
save http://beta16.flarum.localhost/assets/forum-31c35670.js:1
exports http://beta16.flarum.localhost/assets/forum-31c35670.js:822
e http://beta16.flarum.localhost/assets/forum-31c35670.js:1
Expected Behavior
It should be possible to pass an empty value for hasOne relationships, just like it's possible to pass an empty array for hasMany relationships.
Environment
- Flarum version: beta 16
Possible Solution
The problem is here:
If the relationship value isn't an array, it's passed to Model.getIdentifier without checking if it's null.
Either Model.getIdentifier should pass through null values, or Model.getIdentifier should not be called if the value is null.
Additional Context
I'm using this in a yet unreleased extension. As a workaround I am using a local patch that makes Model.getIdentifier return null if the model argument is null.