Question

Please forgive me as I am a beginner to doctrine. I am writing an application to parse some sports data.

I have a simple OneToMany Team in relationship to Players.

class Team
    {

     /**
     * @ORM\OneToMany(targetEntity="Player", mappedBy="team")
     */
     protected $players;

However, I am now creating my Game entity which should have exactly two team objects--a visiting and a home team. To me this seems as two unique one-to-many relationships, but maybe I am overthinking and it would easier as a many-to-many relationship instead.

I would appreciate help in correctly building the entities for this configuration.

Was it helpful?

Solution

In Game class you should create two object with ManyToOne like this:

/**
 * @var Team
 *
 * @ORM\ManyToOne(targetEntity="Team")
 */
private $homeTeam;

/**
 * @var Team
 *
 * @ORM\ManyToOne(targetEntity="Team")
 */
private $awayTeam;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top