Functional test for addManyToOne database column mapping #635

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
4 participants

When the PHPDriver is used to create a ManyToOne relationship with a table which has a primary key other than id the primary key is not associated correctly.

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2376

tests/Doctrine/Tests/ORM/Functional/Ticket/AddManyToOne.php
+ $this->_em->getClassMetadata('Doctrine\Tests\Models\AddManyToOne\Reference'),
+ ));
+
+ $this->assertNotEquals('CREATE TABLE Reference (id INTEGER NOT NULL, user_id INTEGER DEFAULT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_2C52CBB0A76ED395 FOREIGN KEY (user_id) REFERENCES User (id) NOT DEFERRABLE INITIALLY IMMEDIATE)', $sql[1]);
@stof

stof Mar 27, 2013

Member

Checking that it is different is useless IMO as you are checking the value itself just after

@TomHAnderson TomHAnderson referenced this pull request in tawfekov/ZF2EntityAudit Mar 29, 2013

Closed

Bind library to ZFCUser #10

Owner

beberlei commented Mar 30, 2013

You have to use addJoinColumn() to deviate from the default join columns, which is id by dfeault. You cannot however make this point to a column that is not the primary key, that is not allowed.

Did this help already? If not, please reopen.

@beberlei beberlei closed this Mar 30, 2013

This did help. This is the solution I found once pointed to addJoinColumn

$zfcUserMetadata = $metadataFactory->getMetadataFor(\ZF2EntityAudit\Module::getZfcUserEntity());
$builder
    ->createManyToOne('user', $zfcUserMetadata->getName())
    ->addJoinColumn('user_id', $zfcUserMetadata->getSingleIdentifierColumnName())
    ->build();

@TomHAnderson TomHAnderson deleted the TomHAnderson:addManyToOne branch Mar 30, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment