我有一个三个实体:
class User
{
@ORM\OneToMany(targetEntity="Conversation", mappedBy="sender", cascade={"remove"})
private $send_messages;
}
///
class Conversation
{
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="send_messages")
* @ORM\JoinColumn(name="sender_id", referencedColumnName="id", onDelete="SET NULL")
*/
private $sender;
}
///
class Message
{
/**
* @ORM\OneToMany(targetEntity="Conversation", mappedBy="message")
*/
private $conversations;
/**
* @ORM\PreRemove
*/
function onPreRemove()
{
// how remove parent relationship ????
}
}
当我删除用户时,对话被 CASCADE 删除。问题 - 删除时如何删除和消息 Coversation 是消息的最后一个关系。