orm
orm copied to clipboard
🐛❓ Relations without fk, MultiReation of same Class
No duplicates 🥲.
- [x] I have searched for a similar issue in our bug tracker and didn't find any solutions.
What happened?
I try to link the same class twice in another. But the orm didn't let me do.
How can i do something like this :
#[Entity]
class Game extends AbstractModel
{
#[HasOne(target: User::class, innerKey: 'player_1_id', nullable: true, fkCreate: false, fkOnDelete: 'NO ACTION')]
private ?User $player1;
#[HasOne(target: User::class, innerKey: 'player_2_id', nullable: true, fkCreate: false, fkOnDelete: 'NO ACTION')]
private ?User $player2;
#[Entity(table: 'users')]
class User extends AbstractModel
{
#[hasOne(target: Game::class, innerKey: 'current_game_id', nullable: true, fkCreate: false, fkAction: 'NO ACTION')]
private ?Game $currentGame = null;
A game have 2 user ( player_1 and player_2 ) , the user have a reference to the game... but in the game class he can be the player 1 or the player 2 ...
Version
ORM 2.3.4
PHP 8.4
We use HasOne relation when we want to link inner PK with an outer field. Looks like BelongsTo or RefersTo should be used in all the relations there.
but how can you tel currentGame can refers player_1 and player_2 ?
what do you mean?