2013-02-01 43 views
0

父母的關係我有三個實體:Symfony2的:我怎樣才能刪除刪除前

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刪除。問題 - 如何刪除和刪除時消息封面是消息的最後一個關係。

+0

克萊門特你好,我想 ' /** * @ORM \一對多(targetEntity = 「談話」,的mappedBy = 「消息」,orphanRemoval = TRUE) */ 私人談話$; ' 但不工作 –

回答

1

我想你要找的是Doctrine2「Orphan removal

如果A型的實體包含私有實體的引用B,則如果從A到B的引用被移除實體B應也被刪除,因爲它不再使用。

相關問題