Skip to content

Commit

Permalink
Add ActiveRecordInterface::relation() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed May 20, 2024
1 parent dde6315 commit ac2a6d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/AbstractActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,15 @@ public function refresh(): bool
return $this->refreshInternal($record);
}

public function relation(string $name): ActiveRecordInterface|array|null
{
if (array_key_exists($name, $this->related)) {
return $this->related[$name];
}

return $this->retrieveRelation($name);
}

public function resetRelation(string $name): void
{
foreach ($this->relationsDependencies as &$relationNames) {
Expand Down
9 changes: 9 additions & 0 deletions src/ActiveRecordInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ public function getOldPrimaryKey(bool $asArray = false): mixed;
*/
public function getPrimaryKey(bool $asArray = false): mixed;

/**
* Returns the relation object with the specified name.
*
* @param string $name The relation name (case-sensitive).
*
* @return ActiveRecordInterface|array|null The relation object.
*/
public function relation(string $name): ActiveRecordInterface|array|null;

/**
* Returns the relation object with the specified name.
*
Expand Down

0 comments on commit ac2a6d7

Please sign in to comment.