One to Two Relationships in the Doctrine with YAML

I am working on my first Symfony project with Doctrine, and I ran into a problem. I am trying to express a game with two players. The relationship I want to have is PlayerOne and PlayerTwo, each of which is bound to an ID in the Users table. This is part of what I still have:

Game:
  actAs: { Timestampable:- }
  columns:
    id: { type: integer,  notnull: true, unique: true }
    startDate: { type: timestamp, notnull: true }
    playerOne: { type: integer, notnull: true }
    playerTwo: { type: integer, notnull: true }
    winner: { type: integer, notnull:true, default:0 }
  relations:
    User: { onUpdate: cascade, local: playerOne, foreign: id}
    User: { onUpdate: cascade, local: playerTwo, foreign: id}

This does not work. It builds fine, but the SQL that it generates includes only a constraint for playerTwo. I tried several other things:

User: { onUpdate: cascade, local: [playerOne, playerTwo], foreign: id}

also:

    User: [{ onUpdate: cascade, local: playerOne, foreign: id}, { onUpdate: cascade, local: playerTwo, foreign: id}]

Those last two throw errors when I try to build. Is there anyone who understands what I'm trying to do and can help me achieve this?

+3
source share
2 answers

:

  relations:
    UserOne: { onUpdate: cascade, local: playerOne, foreign: id, class: User }
    UserTwo: { onUpdate: cascade, local: playerTwo, foreign: id, class: User }

: "class: User", .

+6

$game- > getUser(), , . , foreignAliases. , (, UserOne, UserTwo) . Doctrine, .

... MySQL Workbench , .

, .

+1

Source: https://habr.com/ru/post/1744862/


All Articles