Using Doctrine2 and PostgreSQL I need to create foreign key constrains DEFERRABLE and INITIALLY DEFERRED
Found options "deferrable" and "deferred" In Doctrine/DBAL/Platforms/PostgreSqlPlatform.php, but have no idea where to use it inside Entity annotations
<?php
/**
* Class User
*
* @ORM\Table(name="jira_issues_changelogs")
* @ORM\Entity
* @package JiraBundle\Entity\Issue
*/
class Changelog
{
/**
* @var string
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="NONE")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="\JiraBundle\Entity\Issue", inversedBy="changelog")
* @ORM\JoinColumn(name="issue", referencedColumnName="id")
Need this column foreign key to be DEFERRABLE INITIALLY DEFERRED
*/
protected $issue;
I hit this same problem with an app I was working on, and came to the conclusion that the DEFERRABLE support in Doctrine DBAL isn't exposed to Doctrine ORM.
The crux of the problem is that in the ORM's SchemaTool the gatherRelationJoinColumns() method doesn't discover any $fkOptions except for onDelete. In order to support adding 'deferrable' there would need to be extended syntax in the ORM mapping layer for it.
In my case it was easier to just patch SchemaTool to add it than coordinate with upstream to add this properly, as there are very few references to people wanting to use advanced FK options on Google.
I thought I'd dump an answer here to avoid other people having to trace the issue themselves...
If someone wants to file a Doctrine ORM issue about it, be my guest!