Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Bug #562: Fix `ActiveRecordInterface::upsert()` to prioritize passed associative values during updates (@Tigrov)
- Bug #561: Fix `ActiveRecordInterface::upsert()` with `$updateProperties = false` (@Tigrov)
- Bug #550: Relation query should be created by related class, not primary model class (@batyrmastyr)
- Enh #571: Optimize performance of `ActiveRecord::get()` method (@Tigrov)

## 1.0.2 March 11, 2026

Expand Down
2 changes: 1 addition & 1 deletion src/AbstractActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ public function db(): ConnectionInterface
/**
* Returns the available property values of an Active Record object.
*
* @return array
* @return array The property values (name-value pairs).
*
* @psalm-return array<string, mixed>
*/
Expand Down
5 changes: 5 additions & 0 deletions src/ActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
*/
class ActiveRecord extends AbstractActiveRecord
{
public function get(string $propertyName): mixed
Comment thread
vjik marked this conversation as resolved.
{
return $this->$propertyName ?? null;
}

public function propertyNames(): array
{
return $this->tableSchema()->getColumnNames();
Expand Down
9 changes: 9 additions & 0 deletions src/Trait/MagicPropertiesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ public function hasRelationQuery(string $name): bool
return method_exists($this, "get{$name}Query");
}

public function get(string $propertyName): mixed
{
if ($propertyName !== 'propertyValues' && property_exists($this, $propertyName)) {
return $this->$propertyName ?? null;
}

return $this->propertyValues[$propertyName] ?? null;
}

public function set(string $propertyName, mixed $value): void
{
if ($this->hasProperty($propertyName)) {
Expand Down
5 changes: 5 additions & 0 deletions src/Trait/PrivatePropertiesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
*/
trait PrivatePropertiesTrait
{
public function get(string $propertyName): mixed
{
return $this->$propertyName ?? null;
}

protected function populateProperty(string $name, mixed $value): void
{
$this->$name = $value;
Expand Down
Loading