[DBAL-313] When creating foreign key constraints, the AbstractPlatform class does not quote the referenced table. Created: 06/Aug/12  Updated: 08/Sep/13  Resolved: 01/May/13

Status: Resolved
Project: Doctrine DBAL
Component/s: Platforms
Affects Version/s: 2.2.2
Fix Version/s: 2.4
Security Level: All

Type: Bug Priority: Minor
Reporter: Marc-André Joyal Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
Labels: None


 Description   

I have a table that is using a reserved MySQL keyword (right) and it's quoted in all the generated SQL but not in the foreign key constraint.

When I use doctrine.php orm:schema-tool:create I get this SQL line:
ALTER TABLE website ADD CONSTRAINT FK_476F5DE7B196EE6E FOREIGN KEY (right_id) REFERENCES right (id)



 Comments   
Comment by Fabio B. Silva [ 26/Aug/12 ]

Hi,

Could you try it with doctrine 2.3 ?
There are lot of changes about quotes.
if it fails even with 2.3 changes please attach your entities.

Thanks..

Comment by Padraig O'Sullivan [ 30/Aug/12 ]

I verified this is fixed in trunk by creating a test. Worth creating pull request to add test case?

public function testQuotedForeignKeySQL()
{   
    $tableOld = new Table("website");
    $tableOld->addColumn('right_id', 'integer');
    $tableOld->addUnnamedForeignKeyConstraint('right', array('right_id'), array('id'));

    $sqls = array();
    foreach ($tableOld->getForeignKeys() AS $fk) {
        $sqls[] = $this->platform->getCreateForeignKeySQL($fk, $tableOld);
    }   

    $this->assertEquals(array("ALTER TABLE website ADD CONSTRAINT FK_476F5DE754976835 FOREIGN KEY (right_id) REFERENCES `right` (id)"), $sqls);
}  
Comment by Christophe Coevoet [ 30/Aug/12 ]

Can you paste your mapping for your right entity ?

Comment by Alexander [ 09/Feb/13 ]

Can you provide us with more feedback?

Comment by Benjamin Eberlei [ 01/May/13 ]

Seems fixed as per comment of Patrick.

Generated at Fri Apr 25 00:07:14 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.