Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(hasOne): do not create links for undefined or null keys
  • Loading branch information
nickescallon committed Aug 1, 2016
commit ff87b83cf175abb41cb64180f5291ced5775692d
3 changes: 3 additions & 0 deletions src/Relation.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ utils.addHiddenPropsToTarget(Relation.prototype, {

// e.g. user hasMany post via "foreignKey", so find all posts of user
findExistingLinksByForeignKey (id) {
if (id === undefined || id === null) {
return
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or we could rework this method such that it returns an empty array in this case.

return this.relatedCollection.filter({
[this.foreignKey]: id
})
Expand Down
2 changes: 1 addition & 1 deletion src/Relation/HasOne.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const HasOneRelation = Relation.extend({
const recordId = utils.get(record, relatedMapper.idAttribute)
const records = this.findExistingLinksByForeignKey(recordId)

if (records.length) {
if (records && records.length) {
return records[0]
}
}
Expand Down