• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

290
Views
How to make Doctrine PostgreSQL Foreign Key constrain DEFERRABLE

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;
almost 3 years ago · Santiago Trujillo
1 answers
Answer question

0

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!

almost 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error