You should have only one column with the foreign key in those two tables. In this case in the address-table.
In the User-entity (the reverse side) you then say: @ORM\OneToOne(targetEntity="Address", mappedBy="user" ) See: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#one-to-one-bidirectional It was not wrong to have an address_id as auto-increment, besides an auto-incremented user_id. It is not useful in this one-to-one relationship, because if a user has 1 address, you can just as well take the user_id as primary key for the address. But I can imagine you might want to keep the door open for more addresses per user in which case it would become a one-to-many relationship and then it could be convenient that you allready have a primary key of its own for the addresses. On Sunday, 25 May 2014 09:45:47 UTC+2, João Carlos Santa Ana wrote: > > Notice: Undefined index: user in > C:\RDM\rede-market-1\Rede-Market-0\vendor\doctrine\orm\lib\Doctrine\ORM\UnitOfWork.php > > on line *2611* > > Em domingo, 25 de maio de 2014 04h44min11s UTC-3, João Carlos Santa Ana > escreveu: >> >> Thanks for responding. Now already different. The second mistake was >> corrected, but I'm having trouble referencing class >> >> class User { >> /** >> * >> * @var \Address >> * @ORM\OneToOne(targetEntity="Address") >> * @ORM\JoinColumns({ >> * @ORM\JoinColumn(name="id", referencedColumnName="user") >> * }) >> */ >> private $userAddress; >> >> >> >> class Address { >> /** >> * @var \User >> * >> * @ORM\OneToOne(targetEntity="User") >> * @ORM\JoinColumns({ >> * @ORM\JoinColumn(name="user", referencedColumnName="id") >> * }) >> */ >> private $user; >> >> >> >> >> Em domingo, 25 de maio de 2014 04h13min13s UTC-3, Parsifal escreveu: >>> >>> As about your first error: in OneToOne case, joining coloumn of both >>> sides must be primary key, in owning side must be auto incremented and in >>> inverse side not. I guess in your Addess entity you have a separate id >>> coloumn? If yes drop it and set AdressId as a primary key but not auto >>> incremented. Also in your owning side, e.g. User entity, i don't see a >>> mappedBy. You need to add it. >>> >> -- You received this message because you are subscribed to the Google Groups "doctrine-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/doctrine-user. For more options, visit https://groups.google.com/d/optout.
