-
Notifications
You must be signed in to change notification settings - Fork 1.4k
PHPORM-148 Fix null
in datetime
fields and reset time in date
field with custom format
#2741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
730a5be
6c54739
b7852f5
dc73661
26e1b81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,9 +205,10 @@ protected function transformModelValue($key, $value) | |
if ($this->hasCast($key) && $value instanceof CarbonInterface) { | ||
$value->settings(array_merge($value->getSettings(), ['toStringFormat' => $this->getDateFormat()])); | ||
|
||
// "date" cast resets the time to 00:00:00. | ||
$castType = $this->getCasts()[$key]; | ||
if ($this->isCustomDateTimeCast($castType) && str_starts_with($castType, 'date:')) { | ||
$value->startOfDay(); | ||
if (str_starts_with($castType, 'date:') || str_starts_with($castType, 'immutable_date:')) { | ||
$value = $value->startOfDay(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
|
@@ -315,19 +316,6 @@ protected function fromDecimal($value, $decimals) | |
return new Decimal128($this->asDecimal($value, $decimals)); | ||
} | ||
|
||
/** @inheritdoc */ | ||
protected function castAttribute($key, $value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the removal of this method what actually fixes the null-handling issue cited in PHPORM-148? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The actual fix is more in |
||
{ | ||
$castType = $this->getCastType($key); | ||
|
||
return match ($castType) { | ||
'immutable_custom_datetime','immutable_datetime' => str_starts_with($this->getCasts()[$key], 'immutable_date:') ? | ||
$this->asDate($value)->toImmutable() : | ||
$this->asDateTime($value)->toImmutable(), | ||
Comment on lines
-324
to
-326
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cast types There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How does I did note that the function you linked already handles:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
default => parent::castAttribute($key, $value) | ||
}; | ||
} | ||
|
||
/** @inheritdoc */ | ||
public function attributesToArray() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The is no method to check a "date" cast, as opposed to "datetime" cast that keep the time.