I have two Entities and a Join table for Many-To-Many relation:
Entities/Product.php
namespace App\Entities;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Table(name="product")
* @ORM\Entity(repositoryClass="App\Repositories\ProductRepository")
*/
class Product
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*
* @var int
*/
private $id;
/**
* Many Products have Many Processes
*
* @ORM\ManyToMany(targetEntity="Process", inversedBy="products")
* @ORM\JoinTable(name="product_process")
*
* @var \Doctrine\Common\Collections\ArrayCollection
*/
private $processes;
public function __construct()
{
$this->processes = new ArrayCollection();
}
}
Entities/Process.php
namespace App\Entities;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Table(name="process")
* @ORM\Entity(repositoryClass="App\Repositories\ProcessRepository")
*/
class Process
{
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*
* @var int
*/
private $id;
/**
* Many Processes have Many Products
*
* @ORM\ManyToMany(targetEntity="Product", mappedBy="processes")
*
* @var \Doctrine\Common\Collections\ArrayCollection
*/
private $products;
public function __construct()
{
$this->products = new ArrayCollection();
}
}
When running doctrine:migrations:diff command it created product
, process
and product_process
tables.
I want to create indexes and foreign keys on the product_process
join table.
Is this possible through Doctrine ORM annotations on one of the other two Entities (Product
or Process
)?