4
我完全新的教義,所以請與我裸...刪除關係學說
在最簡單的,因爲我有一個用戶和類別類,用戶可以屬於多個類別..定義爲這樣
class Application_Model_User {
public function __construct() {
$this->userCategory = new ArrayCollection();
}
/**
* Unidirectional - Users have multiple categories they belong to
*
* @ManyToMany(targetEntity="Application_Model_Category")
* @JoinTable(name="user_category",
* joinColumns={@JoinColumn(name="user", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="category", referencedColumnName="id")}
*)
*/
}
private $userCategory;
public function getUserCategories() {
return $this->userCategory;
}
}
添加類別的用戶很容易,但我不明白,或從文檔的看我怎麼會刪除特定關係......舉例來說,如果我做了
$thing = $em->getRepository('Application_Model_User');
$result = $thing->findOneBy(array(
'id' => (int) 5
));
foreach($result->getUserCategories() as $category) {
if($category->getName() == 'Another Sub Cat') {
// Delete this relationship
}
}
$em->flush();
我能刪除e關係,如果我使用remove刪除實體,那麼整個類別將被刪除?任何線索讚賞!