diff --git a/src/BaseActiveRecordTrait.php b/src/BaseActiveRecordTrait.php index c5061b1ac..966e6e429 100644 --- a/src/BaseActiveRecordTrait.php +++ b/src/BaseActiveRecordTrait.php @@ -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); } } diff --git a/tests/Stubs/ActiveRecord/Customer.php b/tests/Stubs/ActiveRecord/Customer.php index 9029d7072..1688819f6 100644 --- a/tests/Stubs/ActiveRecord/Customer.php +++ b/tests/Stubs/ActiveRecord/Customer.php @@ -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']);