-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
Hi,
if a column is cast to json, and you want to do a partial update with the notation "myJsonField->firstname" it does not work, as the custom setAttribute still wants to deal with it.
Simply adding a return statement when you detect a "->" fixes the problem, the call to the parent::setAttribute() already deals with it.
public function setAttribute($key, $value)
{
parent::setAttribute($key, $value);
//don't deal with json casting, already done in the call above
if(str_contains($key,'->')) return;
$value = $this->attributes[$key];
// Check if we still have a DateTime object due to custom formatting and convert it to a string to write to FM.
// Normally the SQL grammar would handle converting DateTime objects and SQL doesn't care about extra time data,
// but FileMaker does, so we have to convert at this point and strip out times.
//
// We could convert the DateTime to a string at the time when we're preparing the API call, but at that point
// we won't be in the model and won't have access to the cast type to determine if we should strip out the
// time data.
if ($value instanceof DateTime) {
$value = $value->format($this->dateFormat);
}
// When writing dates the regular datetime format won't work, so we have to get JUST the date value
// check the key's cast to see if it is cast to a date or custom date:format
$castType = $this->getCasts()[$key] ?? '';
$isDate = $castType == 'date' || str_starts_with($castType, 'date:');
if ($isDate && ($value !== null)) {
$value = Arr::first(explode(' ', $value));
}
// FileMaker can't handle true and false, so we need to change to 1 and 0
if (is_bool($value)) {
$value = $value ? 1 : 0;
}
$this->attributes[$key] = $value;
return $this;
}
Metadata
Metadata
Assignees
Labels
No labels