Skip to content

Commit

Permalink
Fix setting value for an attribute when AR class has get method for t…
Browse files Browse the repository at this point in the history
…he attribute
  • Loading branch information
Tigrov committed Dec 13, 2023
1 parent 41c6691 commit 2283833
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/BaseActiveRecordTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ public function __set(string $name, mixed $value): void
$this->resetDependentRelations($name);
}
$this->attributes[$name] = $value;
}

if (method_exists($this, 'get' . ucfirst($name))) {
} elseif (method_exists($this, 'get' . ucfirst($name))) {
throw new InvalidCallException('Setting read-only property: ' . static::class . '::' . $name);
}
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Stubs/ActiveRecord/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ public function getTableName(): string
return 'customer';
}

public function getName(): string
{
return $this->name;
}

public function getProfile(): ActiveQuery
{
return $this->hasOne(Profile::class, ['id' => 'profile_id']);
Expand Down

0 comments on commit 2283833

Please sign in to comment.