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
2 changes: 1 addition & 1 deletion src/ActiveQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ private function createInstance(): static
->having($this->having)
->setUnions($this->union)
->params($this->params)
->withQueries($this->withQueries);
->withQueries(...$this->withQueries);
}

private function populateOne(array $row): ActiveRecordInterface|array
Expand Down
5 changes: 5 additions & 0 deletions src/ActiveQueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ public function asArray(bool|null $value = true): static;
*/
public function with(array|string ...$with): static;

/**
* @return array A list of relations that this query should be performed with.
*/
public function getWith(): array;

/**
* Specifies the relation associated with the junction table for use in a relational query.
*
Expand Down
3 changes: 2 additions & 1 deletion src/ActiveQueryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
trait ActiveQueryTrait
{
private bool|null $asArray = null;
private array $with = [];

/**
* Sets the {@see asArray} property.
Expand Down Expand Up @@ -146,7 +147,7 @@ protected function createModels(array $rows): array
* @psalm-param non-empty-list<ActiveRecordInterface|array> $models
* @psalm-param-out non-empty-list<ActiveRecordInterface|array> $models
*/
public function findWith(array $with, array &$models): void
private function findWith(array $with, array &$models): void
{
$primaryModel = reset($models);

Expand Down
14 changes: 14 additions & 0 deletions tests/ActiveQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ public function testGetJoinWith(): void
$this->assertEquals([[['profile'], true, 'LEFT JOIN']], $query->getJoinWith());
}

public function testGetWith(): void
{
$query = Customer::query();

$this->assertSame([], $query->getWith());

$query->with('orders');
$this->assertSame(['orders'], $query->getWith());

$query = Customer::query();
$query->with('orders', 'profile');
$this->assertSame(['orders', 'profile'], $query->getWith());
}

public function testInnerJoinWith(): void
{
$query = Customer::query();
Expand Down