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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@ public static function isIgnoringTouch($class = null)
{
$class = $class ?: static::class;

if (! get_class_vars($class)['timestamps'] || ! $class::UPDATED_AT) {
return true;
}

foreach (static::$ignoreOnTouch as $ignoredClass) {
if ($class === $ignoredClass || is_subclass_of($class, $ignoredClass)) {
return true;
Expand Down
33 changes: 33 additions & 0 deletions tests/Database/DatabaseEloquentModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,27 @@ protected function addMockConnection($model)
return new BaseBuilder($connection, $grammar, $processor);
});
}

public function testTouchingModelWithTimestamps()
{
$this->assertFalse(
Model::isIgnoringTouch(Model::class)
);
}

public function testNotTouchingModelWithUpdatedAtNull()
{
$this->assertTrue(
Model::isIgnoringTouch(EloquentModelWithUpdatedAtNull::class)
);
}

public function testNotTouchingModelWithoutTimestamps()
{
$this->assertTrue(
Model::isIgnoringTouch(EloquentModelWithoutTimestamps::class)
);
}
}

class EloquentTestObserverStub
Expand Down Expand Up @@ -2303,3 +2324,15 @@ class EloquentModelEventObjectStub extends Model
'saving' => EloquentModelSavingEventStub::class,
];
}

class EloquentModelWithoutTimestamps extends Model
{
protected $table = 'stub';
public $timestamps = false;
}

class EloquentModelWithUpdatedAtNull extends Model
{
protected $table = 'stub';
const UPDATED_AT = null;
}