Reverse mapping from database

New topics about Symfony 2 should go here

Moderators: dcobalt, tiagojsag

Reverse mapping from database

Postby gao » Wed Jul 13, 2011 1:14 pm

Hello. I have a database with this tables:

users:
email VARCHAR(100) PK
password VARCHAR(128)
session_id VARCHAR(45)


user_profile:
email VARCHAR(100) PK FK(users.email)
name VARCHAR(255)

When I execute the command:
php app/console doctrine:mapping:convert yml ./src/Test/AccountsBundle/Resources/config/doctrine/metadata/orm --from-database --force

I get the error:
[Doctrine\ORM\Mapping\MappingException]
Property "email" in "UserProfile" was already declared, but it must be declared only once


Any idea?

Regards
gao
Junior Member
 
Posts: 2
Joined: Wed Jul 13, 2011 1:10 pm

Re: Reverse mapping from database

Postby jfgrissom » Thu Jul 14, 2011 8:57 pm

Hi Gao,

I googled and found this:
http://www.doctrine-project.org/jira/br ... y-tabpanel

They say, "It's because a foreign key is a component of the primary key."

If I understand what they are saying... simply change your primary key on user_profile. (make it an id instead of an email.)

To test my theory out... If you can do it... change your PK on the user_profile.

Generally foreign key constraints are not primary/super keys of the constrained table...

As an example:
sometable
id
name

someOtherTable
id
someTable.id (This is the constrained field.)

In this way you can create other tables with the foreign keys of both and it can still be referrenced by it's own id.

yetAnotherTable
id
someTable.id (field constrained to someTable's id)
someOtherTable.id (field constrained to someOtherTable's id)

Hope this helps!
:D~:-D~:grin:
The Principle Of Antagonism:
A protagonist and his story can only be as intellectually fascinating and emotionally compelling as the forces of antagonism make him.
---Robert McKee
http://jfgrissom.wordpress.com
User avatar
jfgrissom
Faithful Member
 
Posts: 225
Joined: Tue Jan 25, 2011 7:24 pm
Location: San Diego

Re: Reverse mapping from database

Postby lunix » Tue Jul 31, 2012 4:30 pm

I had the same issue and followed the above steps and everything worked out. Thanks much
lunix
Junior Member
 
Posts: 1
Joined: Tue Jul 31, 2012 4:29 pm


Return to General Symfony 2 discussion

Who is online

Users browsing this forum: hatembr and 9 guests