Skip to content

Commit 3480cdb

Browse files
authored
Fix resolveClassAttribute() cache key omitting the property (#60815)
1 parent 5c5c1f3 commit 3480cdb

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2678,7 +2678,7 @@ protected static function resolveClassAttribute(string $attributeClass, ?string
26782678
{
26792679
$class ??= static::class;
26802680

2681-
$cacheKey = $class.'@'.$attributeClass;
2681+
$cacheKey = $class.'@'.$attributeClass.'@'.$property;
26822682

26832683
if (array_key_exists($cacheKey, static::$classAttributes)) {
26842684
return static::$classAttributes[$cacheKey];

tests/Database/DatabaseEloquentModelAttributesTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,23 @@ public function test_is_ignoring_touch_with_timestamps_attribute(): void
420420
$this->assertFalse(ModelWithFillableAttribute::isIgnoringTouch());
421421
}
422422

423+
public function test_is_ignoring_touch_after_model_is_constructed(): void
424+
{
425+
new ModelWithTableAndTimestampsFalseAttribute;
426+
427+
$this->assertTrue(ModelWithTableAndTimestampsFalseAttribute::isIgnoringTouch());
428+
}
429+
430+
public function test_table_and_timestamps_attributes_apply_after_is_ignoring_touch(): void
431+
{
432+
ModelWithTableAndTimestampsFalseAttribute::isIgnoringTouch();
433+
434+
$model = new ModelWithTableAndTimestampsFalseAttribute;
435+
436+
$this->assertSame('collision_table', $model->getTable());
437+
$this->assertFalse($model->usesTimestamps());
438+
}
439+
423440
public function test_trait_initializer_merges_appends_with_attribute(): void
424441
{
425442
$model = new ModelWithAppendsAttributeAndTrait;
@@ -564,6 +581,12 @@ class ModelWithTimestampsAttributeAndProperty extends Model
564581
public $timestamps = false;
565582
}
566583

584+
#[Table(name: 'collision_table', timestamps: false)]
585+
class ModelWithTableAndTimestampsFalseAttribute extends Model
586+
{
587+
//
588+
}
589+
567590
#[Table(dateFormat: 'U')]
568591
class ModelWithDateFormatAttribute extends Model
569592
{

0 commit comments

Comments
 (0)