Skip to content

Commit 18beaae

Browse files
committed
feat(model): serialize all fields in toJsonApi when model is new
1 parent 80eccc6 commit 18beaae

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/lib/model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ BaseModel.prototype.toJsonApi = function () {
376376
};
377377

378378
for (const [attribute, options] of Object.entries(this.schema.attributes)) {
379-
if (!this.isModified(attribute)) continue;
379+
if (!this.isNew && !this.isModified(attribute)) continue;
380380

381381
let value = this.get(attribute);
382382
if (options?.transform) {
@@ -391,7 +391,7 @@ BaseModel.prototype.toJsonApi = function () {
391391
}
392392

393393
for (const [relationship, options] of Object.entries(this.schema.relationships)) {
394-
if (!this.isModified(relationship)) continue;
394+
if (!this.isNew && !this.isModified(relationship)) continue;
395395

396396
const value = this.get(relationship) as ModelInstance<Record<string, any>> | ModelInstance<Record<string, any>>[] | null;
397397

0 commit comments

Comments
 (0)