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
8 changes: 4 additions & 4 deletions src/AbstractActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public function link(string $relationName, ActiveRecordInterface $arClass, array
if (is_array($via)) {
[$viaName, $viaRelation] = $via;
/** @psalm-var ActiveQueryInterface $viaRelation */
$viaClass = $viaRelation->getARInstance();
$viaClass = $viaRelation->getArInstance();
// unset $viaName so that it can be reloaded to reflect the change.
/** @psalm-var string $viaName */
unset($this->related[$viaName]);
Expand Down Expand Up @@ -825,7 +825,7 @@ public function unlink(string $relationName, ActiveRecordInterface $arClass, boo
if (is_array($viaRelation)) {
[$viaName, $viaRelation] = $viaRelation;
/** @psalm-var ActiveQueryInterface $viaRelation */
$viaClass = $viaRelation->getARInstance();
$viaClass = $viaRelation->getArInstance();
/** @psalm-var string $viaName */
unset($this->related[$viaName]);
}
Expand Down Expand Up @@ -941,7 +941,7 @@ public function unlinkAll(string $relationName, bool $delete = false): void
if (is_array($viaRelation)) {
[$viaName, $viaRelation] = $viaRelation;
/** @psalm-var ActiveQueryInterface $viaRelation */
$viaClass = $viaRelation->getARInstance();
$viaClass = $viaRelation->getArInstance();
/** @psalm-var string $viaName */
unset($this->related[$viaName]);
} else {
Expand Down Expand Up @@ -984,7 +984,7 @@ public function unlinkAll(string $relationName, bool $delete = false): void
}
}
} else {
$relatedModel = $relation->getARInstance();
$relatedModel = $relation->getArInstance();

$link = $relation->getLink();
if (!$delete && count($link) === 1 && is_array($this->get($b = reset($link)))) {
Expand Down
16 changes: 8 additions & 8 deletions src/ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
final public function __construct(
protected string|ActiveRecordInterface|Closure $arClass
) {
parent::__construct($this->getARInstance()->db());
parent::__construct($this->getArInstance()->db());
}

public function each(): DataReaderInterface
Expand Down Expand Up @@ -273,7 +273,7 @@ public function populate(array $rows): array
*/
private function removeDuplicatedRows(array $rows): array
{
$instance = $this->getARInstance();
$instance = $this->getArInstance();
$pks = $instance->primaryKey();

if (empty($pks)) {
Expand Down Expand Up @@ -416,7 +416,7 @@ public function buildJoinWith(): void

$this->join = [];

$arClass = $this->getARInstance();
$arClass = $this->getArInstance();

foreach ($this->joinWith as [$with, $eagerLoading, $joinType]) {
$this->joinWithRelations($arClass, $with, $joinType);
Expand Down Expand Up @@ -517,7 +517,7 @@ private function joinWithRelations(ActiveRecordInterface $arClass, array $with,
}

if ($relation instanceof ActiveQueryInterface) {
$primaryModel = $relation->getARInstance();
$primaryModel = $relation->getArInstance();
$parent = $relation;
}

Expand Down Expand Up @@ -779,7 +779,7 @@ public function getTablesUsedInFrom(): array

protected function getPrimaryTableName(): string
{
return $this->getARInstance()->tableName();
return $this->getArInstance()->tableName();
}

public function getOn(): array|string|null
Expand All @@ -800,7 +800,7 @@ public function getSql(): string|null
return $this->sql;
}

public function getARClass(): string|ActiveRecordInterface|Closure
public function getArClass(): string|ActiveRecordInterface|Closure
{
return $this->arClass;
}
Expand All @@ -809,7 +809,7 @@ public function findByPk(array|float|int|string $values): array|ActiveRecordInte
{
$values = (array) $values;

$arInstance = $this->getARInstance();
$arInstance = $this->getArInstance();
$primaryKey = $arInstance->primaryKey();

if (empty($primaryKey)) {
Expand Down Expand Up @@ -845,7 +845,7 @@ public function sql(string|null $value): static
return $this;
}

public function getARInstance(): ActiveRecordInterface
public function getArInstance(): ActiveRecordInterface
{
if ($this->arClass instanceof ActiveRecordInterface) {
return clone $this->arClass;
Expand Down
4 changes: 2 additions & 2 deletions src/ActiveQueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public function getSql(): string|null;
*
* @psalm-return ARClass
*/
public function getARClass(): string|ActiveRecordInterface|Closure;
public function getArClass(): string|ActiveRecordInterface|Closure;

public function on(array|string|null $value): static;

Expand Down Expand Up @@ -455,7 +455,7 @@ public function getLink(): array;
* @throws NotInstantiableException
* @return ActiveRecordInterface The model instance associated with this query.
*/
public function getARInstance(): ActiveRecordInterface;
public function getArInstance(): ActiveRecordInterface;

/**
* @return bool Whether this query represents a relation to more than one record.
Expand Down
4 changes: 2 additions & 2 deletions src/ActiveQueryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function createModels(array $rows): array
$models = [];

foreach ($rows as $row) {
$arClass = $this->getARInstance();
$arClass = $this->getArInstance();
$arClass->populateRecord($row);

$models[] = $arClass;
Expand Down Expand Up @@ -159,7 +159,7 @@ public function findWith(array $with, array &$models): void
$primaryModel = reset($models);

if (!$primaryModel instanceof ActiveRecordInterface) {
$primaryModel = $this->getARInstance();
$primaryModel = $this->getArInstance();
}

$relations = $this->normalizeRelations($primaryModel, $with);
Expand Down
8 changes: 4 additions & 4 deletions src/ActiveRelationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private function addInverseRelations(array &$result): void
$relatedModel->populateRelation($this->inverseOf, $primaryModel);
}
} else {
$inverseRelation = $this->getARInstance()->relationQuery($this->inverseOf);
$inverseRelation = $this->getArInstance()->relationQuery($this->inverseOf);
$primaryModel = $inverseRelation->getMultiple() ? [$this->primaryModel] : $this->primaryModel;

/** @var array $relatedModel */
Expand Down Expand Up @@ -338,7 +338,7 @@ private function populateInverseRelation(

/** @var ActiveQuery $relation */
$relation = is_array($model)
? $this->getARInstance()->relationQuery($name)
? $this->getArInstance()->relationQuery($name)
: $model->relationQuery($name);

$link = $relation->getLink();
Expand Down Expand Up @@ -492,7 +492,7 @@ private function prefixKeyColumns(array $columnNames): array
{
if (!empty($this->join) || !empty($this->joinWith)) {
if (empty($this->from)) {
$alias = $this->getARInstance()->tableName();
$alias = $this->getArInstance()->tableName();
} else {
$alias = array_key_first($this->from);

Expand Down Expand Up @@ -570,7 +570,7 @@ protected function filterByModels(array $models): void
/** @var string $propertyName */
$propertyName = array_key_first($this->link);

match ($this->getARInstance()->columnType($propertyName)) {
match ($this->getArInstance()->columnType($propertyName)) {
ColumnType::ARRAY => $this->andWhere(new ArrayOverlapsCondition($columnName, $values)),
ColumnType::JSON => $this->andWhere(new JsonOverlapsCondition($columnName, $values)),
default => $this->andWhere(new InCondition($columnName, 'IN', $values)),
Expand Down
20 changes: 10 additions & 10 deletions tests/ActiveQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testOptions(): void
$customerQuery = new ActiveQuery(Customer::class);

$query = $customerQuery->on(['a' => 'b'])->joinWith('profile');
$this->assertEquals(Customer::class, $query->getARClass());
$this->assertEquals(Customer::class, $query->getArClass());
$this->assertEquals(['a' => 'b'], $query->getOn());
$this->assertEquals([[['profile'], true, 'LEFT JOIN']], $query->getJoinWith());
$customerQuery->resetJoinWith();
Expand Down Expand Up @@ -2499,29 +2499,29 @@ public function testEqual(): void
$this->assertFalse($customerA->equals($customerB));
}

public function testARClassAsString(): void
public function testArClassAsString(): void
{
$query = new ActiveQuery(Customer::class);

$this->assertSame(Customer::class, $query->getARClass());
$this->assertInstanceOf(Customer::class, $query->getARInstance());
$this->assertSame(Customer::class, $query->getArClass());
$this->assertInstanceOf(Customer::class, $query->getArInstance());
}

public function testARClassAsInstance(): void
public function testArClassAsInstance(): void
{
$customer = new Customer();
$query = new ActiveQuery($customer);

$this->assertSame($customer, $query->getARClass());
$this->assertInstanceOf(Customer::class, $query->getARInstance());
$this->assertSame($customer, $query->getArClass());
$this->assertInstanceOf(Customer::class, $query->getArInstance());
}

public function testARClassAsClosure(): void
public function testArClassAsClosure(): void
{
$closure = fn (): Customer => new Customer();
$query = new ActiveQuery($closure);

$this->assertSame($closure, $query->getARClass());
$this->assertInstanceOf(Customer::class, $query->getARInstance());
$this->assertSame($closure, $query->getArClass());
$this->assertInstanceOf(Customer::class, $query->getArInstance());
}
}