0

Users can see campaigns only if they're assigned to them. The fact that they can see campaign doesn't mean that they're participating to it. I want to give the opportunity for user to join to campaign.

I use Bidirectional, ManyToMany relation, table user_campaign was created automatically. Is any possibility to add additional field like participating? I'd rather not to create new table.

Entity User.php

/**
 * @ORM\ManyToMany(targetEntity="Reko\CampaignBundle\Entity\Campaign", inversedBy="users")
 * @ORM\OrderBy({"id" = "DESC"})
 * @ORM\JoinTable(name="user_campaign")
 */
protected $campaigns;

Entity Campaign.php

/**
 * @ORM\ManyToMany(targetEntity="Reko\UserBundle\Entity\User", mappedBy="campaigns")
 */
protected $users;
siwymilek
  • 815
  • 1
  • 6
  • 24
  • Extra data on a `m:n` always means an intermediary entity is needed to carry that extra data. The new entity then has a `1:n` to the two original entities. – Yoshi Sep 02 '16 at 09:18

1 Answers1

0

Basicall what you need is two manytomany relationships between users and campaigns. One representing assignments, one representing participation. Since doctrine can automatically only create one jointable you will have to manually name your two jointables differently in annotations and you're fine!

Sangit
  • 159
  • 2
  • 13