I really hope someone can help me with this because its driving me crazy, something that should be so simple
Database Tables Example (ID is the primary column on all tables)
Exhibitors
id | name | address_line_1
3 | Test Name | Test 123 Street
4 | Test Name 2 | Test 123 Street 1
5 | Test Name 3 | Test 123 Street 2
6 | Test Name 4 | Test 123 Street 2
Shows
id | name | location
7 | The Greatest Show | USA
8 | Super Show | London, UK
9 | A Great Show | Toronto, CA
10 | Fab Show | NEC, Birmingham, UK
Links
id | show_id | exhibitor_id | agent_id | type
1 | 7 | 3 | null | 1
1 | 7 | 5 | null | 1
1 | 8 | 3 | null | 1
1 | 10 | 6 | null | 1
Now the link I'm trying to do is a manytoMany so basically, each show can have multiple exhibitors and vice versa each exhibitor can be assigned to multiple shows. The current entities are creating a whole new table called ppShowExhibLinks which I dont really want it to do but im really stuck ...
The Links table will hold different sorts of links hence the type and agent_id, so somehow I'm trying to get the relationship to do something along the lines of:
$show = new Show(); $show->getExhibitors();
This then does something like "Get all links where show_id is the current show and type is 1"
Then the reverse
$show = new Exhibitor(); $show->getShows(); This then does something like "Get all links where exhibitor_id is the current exhibitor and type is 1"
PS: I know that a new instance of the object wont have any links exhibs/shows but just to demonstate the object.
Entities
/**
* @ORM\Table(name="ppShows")
* @ORM\Entity(repositoryClass="App\Repository\ShowRepository")
*/
class Show
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
protected $name;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
protected $location;
/**
* @var \Doctrine\Common\Collections\Collection|Exhibitor[]
*
* @ORM\ManyToMany(targetEntity="Exhibitor", inversedBy="shows")
* @ORM\JoinTable(
* name="ppShowExhibLinks",
* joinColumns={
* @ORM\JoinColumn(name="show_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="exhibitor_id", referencedColumnName="id")
* }
* )
*/
protected $exhibitors;
********************************************
class Exhibitor
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
protected $name;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
protected $address_line_1;
/**
* @var \Doctrine\Common\Collections\Collection|Show[]
*
* @ORM\ManyToMany(targetEntity="Show", inversedBy="exhibitors")
* @ORM\JoinTable(
* name="ppShowExhibLinks",
* joinColumns={
* @ORM\JoinColumn(name="show_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="exhibitor_id", referencedColumnName="id")
* }
* )
*/
protected $shows;
class Link
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer", options={"default" : 0}, nullable=true)
*/
protected $show_id;
/**
* @ORM\Column(type="integer", options={"default" : 0}, nullable=true)
*/
protected $exhibitor_id;
/**
* @ORM\Column(type="integer", options={"default" : 0}, nullable=true)
*/
protected $agent_id;
/**
* @ORM\Column(type="integer", options={"default" : 1}, nullable=false)
*/
protected $type;