-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\ActiveRecord\Tests\Driver\Pgsql\Stubs; | ||
|
||
use Yiisoft\ActiveRecord\ActiveQueryInterface; | ||
|
||
/** | ||
* Class Item. | ||
*/ | ||
final class Item extends \Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord\Item | ||
{ | ||
public function relationQuery(string $name): ActiveQueryInterface | ||
{ | ||
return match ($name) { | ||
'promotions' => $this->hasMany(Promotion::class, ['item_ids' => 'id']), | ||
default => parent::relationQuery($name), | ||
}; | ||
} | ||
|
||
/** @return Promotion[] */ | ||
public function getPromotions(): array | ||
{ | ||
return $this->relation('promotions'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\ActiveRecord\Tests\Driver\Pgsql\Stubs; | ||
|
||
use Yiisoft\ActiveRecord\ActiveQueryInterface; | ||
use Yiisoft\ActiveRecord\ActiveRecord; | ||
|
||
final class Promotion extends ActiveRecord | ||
{ | ||
public int $id; | ||
/** @var int[] $item_ids */ | ||
public array $item_ids; | ||
public string $title; | ||
|
||
public function getTableName(): string | ||
{ | ||
return '{{%promotion}}'; | ||
} | ||
|
||
public function relationQuery(string $name): ActiveQueryInterface | ||
{ | ||
return match ($name) { | ||
'items' => $this->hasMany(Item::class, ['id' => 'item_ids'])->inverseOf('promotions'), | ||
default => parent::relationQuery($name), | ||
}; | ||
} | ||
|
||
/** @return Item[] */ | ||
public function getItems(): array | ||
{ | ||
return $this->relation('items'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters