Reputation: 403
I try to create a ternary relation whith composite primary keys (3 primary keys):
So I have these entities : Club ($id), Sport ($id) and PlayerSingle ($id)
How can I create a ternary relation with doctrine ?
I try to create this entity (Club__Sport__Player_Single) but in phpmyadmin, there is only id attribute and these 3 primary keys.
/**
* Club__Sport__Player_Single
*
* @ORM\Table(name="club__sport__player_single")
* @ORM\Entity(repositoryClass="Club__Sport__Player_Single_danseRepository")
*/
class Club__Sport__Player_Single
{
/**
* @var int
*
* @ORM\Id
* @ORM\ManyToOne(targetEntity="Club")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id", referencedColumnName="id")
* })
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $club_id;
/**
* @var int
*
* @ORM\ManyToOne(targetEntity="Sport")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id", referencedColumnName="id")
* })
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $sport_id;
/**
* @var int
*
* @ORM\ManyToOne(targetEntity="PlayerSingle")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id", referencedColumnName="id")
* })
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $playerSingle_id;
...
}
Why in phpmyadmin, I have only id attribute and the 3 attributes (club_id, sport_id,playerSingle_id) ??
Upvotes: 1
Views: 332
Reputation: 2106
My advice, use an standard auto-generated id for primary key, and also include the three foreign keys with an unique index for the combination. It look better and has the same result.
Hope this help you.
Upvotes: 1