Reputation: 31
Can you look at the relationship between entities, unfortunately all the time is not working properly. I will be grateful for the help. This is a relation 1 to 1.
User Entity
/**
*
* @ORM\Column(type="string")
*
* @ORM\OneToOne(targetEntity="Structure", mappedBy="user")
*/
protected $structure;
Structure Entity
/**
* @var string
*
* @ORM\Column(name="user", type="string", length=50, unique=false)
* @ORM\OneToOne(targetEntity="User", inversedBy="structure")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
private $user;
Upvotes: 1
Views: 5332
Reputation: 143
Try this one ...
/**
* @ORM\OneToOne(targetEntity="User",
* inversedBy="structure")
*/
private $user;
/**
*@ORM\OneToOne(targetEntity="Structure",mappedBy="user",cascade={"persist","remove"})
*/
private $structure;
Upvotes: 2
Reputation: 31
As suggested by @Albeis in a comment:
Try to remove
@ORM\Column
of both sides...relations itself don't have column..Regards Check http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/association-mapping.html#one-to-one-bidirectional
This solved my problem. The issue was about to remove @ORM\Column of both sides. Thanks for help.
Upvotes: 1
Reputation: 388
/**
* @ORM\OneToOne(targetEntity="Core\UserBundle\Entity\Profile", mappedBy="user")
*/
private $profile;
/**
* @ORM\OneToOne(targetEntity="Core\UserBundle\Entity\User", inversedBy="profile")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id",onDelete="CASCADE")
*/
private $user;
user_id inside profile entity.
if you set onDelete="CASCADE", if you delete user, profile will deleting automatically by mysql.
Upvotes: 0