From e70c4cc8a1e37533ed95dffa2aaec9cac72e9848 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 4 Oct 2022 16:00:48 +0200 Subject: [PATCH 1/5] remove `id` from `fill()` to prevent postgres error --- src/Entries/Entry.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Entries/Entry.php b/src/Entries/Entry.php index e2fff280..5e4a5cb1 100644 --- a/src/Entries/Entry.php +++ b/src/Entries/Entry.php @@ -42,7 +42,6 @@ public function toModel() } return $class::findOrNew($this->id())->fill([ - 'id' => $this->id(), 'origin_id' => $this->origin()?->id(), 'site' => $this->locale(), 'slug' => $this->slug(), From 96c90246cca8602b9681a2afdae679ecc86109ad Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 4 Oct 2022 16:14:37 +0200 Subject: [PATCH 2/5] remove `id` from model --- tests/Entries/EntryTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Entries/EntryTest.php b/tests/Entries/EntryTest.php index 8285cdb3..facbea67 100644 --- a/tests/Entries/EntryTest.php +++ b/tests/Entries/EntryTest.php @@ -44,7 +44,6 @@ public function it_saves_to_entry_model() 'published' => false, 'status' => 'draft', 'origin_id' => null, - 'id' => null, ]); $collection = Collection::make('blog')->title('blog')->routes([ From 195ff957a82081d8aff05f7a74ab55d159c78fa2 Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 4 Oct 2022 16:00:48 +0200 Subject: [PATCH 3/5] remove `id` from `fill()` to prevent postgres error --- src/Entries/Entry.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Entries/Entry.php b/src/Entries/Entry.php index 3344c2e0..1c52887e 100644 --- a/src/Entries/Entry.php +++ b/src/Entries/Entry.php @@ -42,7 +42,6 @@ public function toModel() } return $class::findOrNew($this->id())->fill([ - 'id' => $this->id(), 'origin_id' => $this->origin()?->id(), 'site' => $this->locale(), 'slug' => $this->slug(), From 1013f21475b5164d1daeae7bc2f944c3e1d00c0b Mon Sep 17 00:00:00 2001 From: Lukas Date: Tue, 4 Oct 2022 16:14:37 +0200 Subject: [PATCH 4/5] remove `id` from model --- tests/Entries/EntryTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Entries/EntryTest.php b/tests/Entries/EntryTest.php index 8285cdb3..facbea67 100644 --- a/tests/Entries/EntryTest.php +++ b/tests/Entries/EntryTest.php @@ -44,7 +44,6 @@ public function it_saves_to_entry_model() 'published' => false, 'status' => 'draft', 'origin_id' => null, - 'id' => null, ]); $collection = Collection::make('blog')->title('blog')->routes([ From 787c7786dd53c6942eeec0cbd37a690660d4f92b Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Fri, 11 Nov 2022 15:36:59 -0500 Subject: [PATCH 5/5] Only add id to attributes if defined --- src/Entries/Entry.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Entries/Entry.php b/src/Entries/Entry.php index fc0ab722..5b1fefbb 100644 --- a/src/Entries/Entry.php +++ b/src/Entries/Entry.php @@ -41,7 +41,7 @@ public function toModel() $data['blueprint'] = $this->blueprint; } - return $class::findOrNew($this->id())->fill([ + $attributes = [ 'origin_id' => $this->origin()?->id(), 'site' => $this->locale(), 'slug' => $this->slug(), @@ -53,7 +53,13 @@ public function toModel() 'status' => $this->status(), 'updated_at' => $this->lastModified(), 'order' => $this->order(), - ]); + ]; + + if ($id = $this->id()) { + $attributes['id'] = $id; + } + + return $class::findOrNew($id)->fill($attributes); } public function model($model = null)