Skip to content
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

Merged
merged 5 commits into from Jun 5, 2019

Conversation

Projects
None yet
3 participants
@mxss
Copy link
Contributor

commented May 30, 2019

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

mxss added some commits May 30, 2019

@mxss mxss changed the title [WIP] fix MorphTo Relation ignores parent $timestamp when touching [5.8] fix MorphTo Relation ignores parent $timestamp when touching May 30, 2019

@mxss

This comment has been minimized.

Copy link
Contributor Author

commented May 30, 2019

@driesvints reopened #28658

@staudenmeir

This comment has been minimized.

Copy link
Contributor

commented Jun 1, 2019

We also have to cover cases where timestamps are enabled, but UPDATED_AT is null:

if (! $this->model->usesTimestamps() ||
is_null($this->model->getUpdatedAtColumn())) {
return $values;
}

@@ -294,6 +294,10 @@ public static function isIgnoringTouch($class = null)
{
$class = $class ?: static::class;
if (! get_class_vars($class)['timestamps']) {

This comment has been minimized.

Copy link
@staudenmeir

staudenmeir Jun 1, 2019

Contributor

I would prefer (new $class)->usesTimestamps() to be consistent with existing code.

This comment has been minimized.

Copy link
@mxss

mxss Jun 1, 2019

Author Contributor

We also have to cover cases where timestamps are enabled, but UPDATED_AT is null:

just added test

This comment has been minimized.

Copy link
@mxss

mxss Jun 1, 2019

Author Contributor

@staudenmeir in some cases we're getting abstract classes here for ex.

$this->assertFalse(Model::isIgnoringTouch());

This comment has been minimized.

Copy link
@staudenmeir

staudenmeir Jun 1, 2019

Contributor

Yes, but only in the tests. You can't get an abstract class in a real application. Please adjust the test accordingly.

This comment has been minimized.

Copy link
@mxss

mxss Jun 3, 2019

Author Contributor

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());

This comment has been minimized.

Copy link
@staudenmeir

staudenmeir Jun 3, 2019

Contributor

I think we should move the new code to Relation::touch(). Model::isIgnoringTouch() is only about $ignoreOnTouch, not about timestamps.

mxss added some commits Jun 1, 2019

public function testTouchingModelWithUpdatedAtNull()
{
$this->assertFalse(

This comment has been minimized.

Copy link
@staudenmeir

staudenmeir Jun 1, 2019

Contributor

This case has to return true. You need to cover it by adjusting isIgnoringTouch().

This comment has been minimized.

Copy link
@mxss

mxss Jun 3, 2019

Author Contributor

done

added UPDATED_AT constant check & updated test
Signed-off-by: Max Kovalenko <mxss1998@yandex.ru>

@taylorotwell taylorotwell merged commit 26a22a2 into laravel:5.8 Jun 5, 2019

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.