Skip to content

Commit fd7120c

Browse files
Only fill entry model with id if it already has one, to prevent postgres error (#68)
Co-authored-by: Jason Varga <[email protected]>
1 parent 1bfad36 commit fd7120c

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/Entries/Entry.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ public function toModel()
4141
$data['blueprint'] = $this->blueprint;
4242
}
4343

44-
return $class::findOrNew($this->id())->fill([
45-
'id' => $this->id(),
44+
$attributes = [
4645
'origin_id' => $this->origin()?->id(),
4746
'site' => $this->locale(),
4847
'slug' => $this->slug(),
@@ -54,7 +53,13 @@ public function toModel()
5453
'status' => $this->status(),
5554
'updated_at' => $this->lastModified(),
5655
'order' => $this->order(),
57-
]);
56+
];
57+
58+
if ($id = $this->id()) {
59+
$attributes['id'] = $id;
60+
}
61+
62+
return $class::findOrNew($id)->fill($attributes);
5863
}
5964

6065
public function model($model = null)

tests/Entries/EntryTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public function it_saves_to_entry_model()
4444
'published' => false,
4545
'status' => 'draft',
4646
'origin_id' => null,
47-
'id' => null,
4847
'order' => null,
4948
]);
5049

0 commit comments

Comments
 (0)