Skip to content

Commit 8d0fcb5

Browse files
committed
added support for passing the mod Id directly into withModId()
1 parent 3cca36f commit 8d0fcb5

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,24 @@ The Data API lets you set a [Modification ID](https://help.claris.com/en/data-ap
271271
272272
> Specifying a modification ID ensures that you are editing the current version of a record. If the modification ID value does not match the current modification ID value in the database, the record is not changed.
273273
274-
If you wish to include the modId when editing a record you can call `withModId()` before calling `save()` on the model object. This will send the ModID to FileMaker when updating the record, and will throw a `FileMakerDataApiException` if the ModId does not match.
274+
If you wish to include the modId when editing a record you can call `withModId()` before calling `save()` on the model object. This will send the ModID to FileMaker when updating the record, and will throw a `FileMakerDataApiException` with code `306` if the ModId does not match.
275275
276276
```php
277277
$person->withModId()->save();
278278
```
279279
280280
The modId is automatically set on the model object when you retrieve a record from FileMaker, so you don't need to set it manually.
281281
282+
If you want to set the ModId manually you can do so by either passing the modId into `withModId($myModId)` or calling `setModId($myModId)` on the model object.
283+
284+
285+
```php
286+
287+
// set the ModId and flag it submit the modification ID when saving the record
288+
$person->withModId(12)->save();
289+
290+
```
291+
282292
If you always want the ModId to be included when saving a record, you can set the `$withModId` property to true on your model class.
283293
284294
```php

src/Database/Eloquent/FMModel.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,22 @@ public function setModId($modId): void
227227

228228
/**
229229
* Include the modification Id when editing a record
230+
*
231+
* @param int|string|bool $includeModId This can be an integer to set the ModId or a boolean to include it or not
230232
*/
231-
public function withModId($include = true): static
233+
public function withModId(int|string|bool $includeModId = true): static
232234
{
235+
// check if the parameter is an integer, if not, default to true
236+
if (! is_bool($includeModId)) {
237+
$modId = $includeModId;
238+
239+
// set the mod ID and include it
240+
$this->setModId($modId);
241+
$includeModId = true;
242+
}
243+
233244
// remove any set ModId if the user wishes to remove it
234-
$this->withModId = $include;
245+
$this->withModId = $includeModId;
235246

236247
return $this;
237248
}

0 commit comments

Comments
 (0)