Thanks to visit codestin.com
Credit goes to github.com

Skip to content

πŸ›β“ Relations without fk, MultiReation of same ClassΒ #538

@andrelec1

Description

@andrelec1

No duplicates πŸ₯².

  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions