Skip to content
Merged
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
17 changes: 9 additions & 8 deletions lib/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function __call(string $method, mixed $args): Model|null
$options['conditions'][] = WhereClause::from_underscored_string($this->table()->conn, $attributes, $args, $this->alias_attribute);

$options['limit'] = 1;
$ret = $this->to_a_withOptions($options);
$ret = $this->_to_a($options);

if (0 === count($ret)) {
if ($create) {
Expand Down Expand Up @@ -719,7 +719,7 @@ public function find(): Model|array
$options['conditions'] ??= [];
$options['conditions'][] = $this->pk_conditions($args);

$list = $this->to_a_withOptions($options);
$list = $this->_to_a($options);
if (is_array($args) && count($list) != count($args)) {
throw new RecordNotFound('found ' . count($list) . ', but was looking for ' . count($args));
}
Expand All @@ -741,7 +741,7 @@ public function find(): Model|array
public function take(int $limit = null): Model|array|null
{
$options = array_merge($this->options, ['limit' => $limit ?? 1]);
$models = $this->to_a_withOptions($options);
$models = $this->_to_a($options);

return isset($limit) ? $models : $models[0] ?? null;
}
Expand Down Expand Up @@ -827,7 +827,7 @@ private function firstOrLast(int $limit = null, bool $isAscending): array
}
}

return $this->to_a_withOptions($options);
return $this->_to_a($options);
}

/**
Expand All @@ -837,17 +837,18 @@ private function firstOrLast(int $limit = null, bool $isAscending): array
*/
public function to_a(): array
{
return $this->to_a_withOptions($this->options);
return $this->_to_a($this->options);
}

/**
* Converts relation objects to array with a given options.
*
* @param RelationOptions $options
*
* @throws ActiveRecordException
* @throws Exception\RelationshipException
*
* @return array<TModel> All the rows that matches query. If no rows match, returns []
*/
private function to_a_withOptions(array $options): array
protected function _to_a(array $options): array
{
if ($this->isNone) {
return [];
Expand Down