I have two entities. User and Contact. User and contact have the same property phone_number. I would like to get all contacts with user object if its exists. It is also possible that the same phone number exists in contact table but it doesn't exist in user table.
Below is an annotation in contact entity:
/**
* @ORM\OneToOne(targetEntity="Dlabs\ServiceBundle\Entity\User", mappedBy="contact")
* @ORM\JoinColumn(name="phone", referencedColumnName="phone_number", nullable=true)
*/
private $user;
When I update my schema I get below errors:
[Doctrine\DBAL\DBALException] An exception occurred while executing 'ALTER TABLE contact ADD CONSTRAINT FK_83DFDFA4444F97DD FOREIGN KEY (phone) REFERENCES users (phone_number) NOT DEFERRABLE INITIALLY IMMEDIATE': SQLSTATE[23503]: Foreign key violation: 7 ERROR: insert or update on table "contact" violates foreign key constraint "fk_83dfdfa4444f97dd" DETAIL: Key (phone)=(+38640775xxx) is not present in table "users".
[PDOException] SQLSTATE[23503]: Foreign key violation: 7 ERROR: insert or update on table "contact" violates foreign key constraint "fk_83dfdfa4444f97dd" DETAIL: Key (phone)=(+38640775xxx) is not present in table "users".
Does anyone know in which way I should change my annotations so this will work? Thanks!