score:3

Accepted answer

From the comments I read you want a one-to-one association between Users and Players. You can set it up as unidirectional like this:

class Players
{
    /**
     * @ORM\OneToOne(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Users")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
     */
    private $user;

    // ...
}

This means you will have access to user from player ($player->getUser()). But because it's unidirectional, you won't have access to player from user ($user->getPlayer()). Doctrine is correct when not creating a $player property in Users.

You could define the association the other way around:

class Users
{
    /**
     * @ORM\OneToOne(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Players")
     * @ORM\JoinColumn(name="player_id", referencedColumnName="player_id")
     */
    private $player;

    // ...
}

You can now do $user->getPlayer(), but can't do $player->getUser().

If you want both, you'll have to set it up as a bidirectional association:

class Players
{
    /**
     * @ORM\OneToOne(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Users", inversedBy="player")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="user_id")
     */
    private $user;

    // ...
}

class Users
{
    /**
     * @ORM\OneToOne(targetEntity="VolleyScout\VolleyScoutBundle\Entity\Players", mappedBy="user")
     */
    private $player;

    // ...
}

PS: I highly recommend you name your classes in single form (User and Player), not in plural form (Users and Players), because an instance (object) of those classes will represent 1 user or player (not many users or players).


Related Query

More Query from same tag