Skip to content

Commit b159f2c

Browse files
author
Lee Richmond
committed
Allow setting null belongsTo
1 parent 57a49fd commit b159f2c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/associations.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ export class Base extends Attribute {
1919
}
2020

2121
setter(context: Model, val: any) : void {
22-
if (!val.hasOwnProperty('isRelationship')) {
22+
if (val && !val.hasOwnProperty('isRelationship')) {
2323
if (!(val instanceof Model) && !(Array.isArray(val))) {
2424
val = new this.klass(val);
2525
}
2626
context.relationships[this.name] = val;
27+
} else if (val === null || val === undefined) {
28+
context.relationships[this.name] = val;
2729
}
2830
}
2931
}

0 commit comments

Comments
 (0)