From 907bd7de78e7459dde5f6761ccb08ce6367264f5 Mon Sep 17 00:00:00 2001 From: David Nahodyl Date: Tue, 8 Oct 2024 10:51:35 -0400 Subject: [PATCH 1/2] added withModId function --- src/Database/Eloquent/FMEloquentBuilder.php | 5 +++++ src/Database/Eloquent/FMModel.php | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Database/Eloquent/FMEloquentBuilder.php b/src/Database/Eloquent/FMEloquentBuilder.php index a173b4b..42325ef 100644 --- a/src/Database/Eloquent/FMEloquentBuilder.php +++ b/src/Database/Eloquent/FMEloquentBuilder.php @@ -167,6 +167,11 @@ public function editRecord() } } + // set the ModID if that option is set on the model + if ($model->withModId()) { + $this->query->modId($model->getModId()); + } + if ($fieldsToWrite->count() > 0 || count($modifiedPortals) > 0) { // we have some regular text fields to update // forward this request to a base query builder to execute the edit record request diff --git a/src/Database/Eloquent/FMModel.php b/src/Database/Eloquent/FMModel.php index 47644a4..47ab340 100644 --- a/src/Database/Eloquent/FMModel.php +++ b/src/Database/Eloquent/FMModel.php @@ -65,6 +65,8 @@ abstract class FMModel extends Model */ protected $modId; + protected $useModId = false; + /** * The "type" of the primary key ID. FileMaker uses UUID strings by default. * @@ -219,6 +221,17 @@ public function setModId($modId): void $this->modId = $modId; } + /** + * Include the modification Id when editing a record + */ + public function withModId($include = true): self + { + // remove any set ModId if the user wishes to remove it + $this->useModId = $include; + + return $this; + } + public function getReadOnlyFields() { return $this->readOnlyFields; From f1545c78c4bb5d3fd26e1528218d50a729a365ae Mon Sep 17 00:00:00 2001 From: David Nahodyl Date: Tue, 8 Oct 2024 14:50:55 -0400 Subject: [PATCH 2/2] Changed return type for `withModId`. Added `usingModId` public accessor. Fixed wrong check for usingModId --- src/Database/Eloquent/FMEloquentBuilder.php | 2 +- src/Database/Eloquent/FMModel.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Database/Eloquent/FMEloquentBuilder.php b/src/Database/Eloquent/FMEloquentBuilder.php index 42325ef..30bfa79 100644 --- a/src/Database/Eloquent/FMEloquentBuilder.php +++ b/src/Database/Eloquent/FMEloquentBuilder.php @@ -168,7 +168,7 @@ public function editRecord() } // set the ModID if that option is set on the model - if ($model->withModId()) { + if ($model->usingModId()) { $this->query->modId($model->getModId()); } diff --git a/src/Database/Eloquent/FMModel.php b/src/Database/Eloquent/FMModel.php index 47ab340..63c3d1e 100644 --- a/src/Database/Eloquent/FMModel.php +++ b/src/Database/Eloquent/FMModel.php @@ -224,7 +224,7 @@ public function setModId($modId): void /** * Include the modification Id when editing a record */ - public function withModId($include = true): self + public function withModId($include = true): static { // remove any set ModId if the user wishes to remove it $this->useModId = $include; @@ -232,6 +232,11 @@ public function withModId($include = true): self return $this; } + public function usingModId(): bool + { + return $this->useModId; + } + public function getReadOnlyFields() { return $this->readOnlyFields;