-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.8] fix MorphTo Relation ignores parent $timestamp when touching #28670
[5.8] fix MorphTo Relation ignores parent $timestamp when touching #28670
Conversation
@driesvints reopened #28658 |
We also have to cover cases where timestamps are enabled, but framework/src/Illuminate/Database/Eloquent/Builder.php Lines 861 to 864 in 0ef0134
|
@@ -294,6 +294,10 @@ public static function isIgnoringTouch($class = null) | |||
{ | |||
$class = $class ?: static::class; | |||
|
|||
if (! get_class_vars($class)['timestamps']) { |
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.
I would prefer (new $class)->usesTimestamps()
to be consistent with existing code.
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.
We also have to cover cases where timestamps are enabled, but UPDATED_AT is null:
just added test
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.
@staudenmeir in some cases we're getting abstract classes here for ex.
$this->assertFalse(Model::isIgnoringTouch()); |
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.
Yes, but only in the tests. You can't get an abstract class in a real application. Please adjust the test accordingly.
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.
Yes, but only in the tests. You can't get an abstract class in a real application.
OK, but If I use (new $class)->usesTimestamps()
6 more test are failing (not including mine) - what to do with that?
For example this one:
$this->assertFalse(Model::isIgnoringTouch()); |
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.
I think we should move the new code to Relation::touch()
. Model::isIgnoringTouch()
is only about $ignoreOnTouch
, not about timestamps.
|
||
public function testTouchingModelWithUpdatedAtNull() | ||
{ | ||
$this->assertFalse( |
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.
This case has to return true
. You need to cover it by adjusting isIgnoringTouch()
.
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.
done
Signed-off-by: Max Kovalenko <[email protected]>
Fixed bug with touching model which has $timestamps set to false resulting in Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such column: updated_at
for source issue and more details see #28638