我有一个具有一对多关系的类用户,ArticleVote它本身就是一个Association Class(见下文)。
这是我的实体的样子:
class User
{
protected $articlesVotes;
}
用户持有一个ArticleVote集合。
虽然 ArticleVote 由基于UserId和 的复合主键引用ArticleId:
class ArticleVote
{
protected $article;
protected $user;
}
现在,假设我想删除ArticleVotefrom User,我自然会这样做,这会导致集合$user->getArticlesVotes()->removeElement($articleVote);中的实体被实际删除,但由于它既是关系又是实体,数据库中的行根本不会被删除。ArticleVote
我知道,我可以做到,$em->remove($articleVote);但我希望我可以从用户集合中删除它以绕过 EntityManager,如果我想删除几个$articleVote呢?
User目前,我通过传递实体在我的模型中创建/删除投票,Article它是我的User实体创建ArticleVote对象并自行附加它,我希望我可以对删除功能具有相同的行为。
有任何想法吗?(哦,顺便说一句,我已经尝试过使用 cascade="remove")