1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-09-15 18:57:05 +00:00

Change ManyToMany between entry & tag

Following https://gist.github.com/Ocramius/3121916

Be sure to remove the related entity when removing an entity.

Let say you have Entry -> EntryTag -> Tag.
If you remove the entry:

 - before that commit, the EntryTag will stay (at least using SQLite).
 - with that commit, the related entity is removed
This commit is contained in:
Jeremy Benoist 2016-05-30 14:34:11 +02:00 committed by Thomas Citharel
parent 6334f2cac1
commit e42b13bcff
4 changed files with 68 additions and 7 deletions

View file

@ -178,7 +178,15 @@ class Entry
/**
* @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
* @ORM\JoinTable
* @ORM\JoinTable(
* name="entry_tag",
* joinColumns={
* @ORM\JoinColumn(name="entry_id", referencedColumnName="id")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
* }
* )
*
* @Groups({"entries_for_user", "export_all"})
*/
@ -526,13 +534,18 @@ class Entry
}
}
$this->tags[] = $tag;
$this->tags->add($tag);
$tag->addEntry($this);
}
public function removeTag(Tag $tag)
{
if (!$this->tags->contains($tag)) {
return;
}
$this->tags->removeElement($tag);
$tag->removeEntry($this);
}
/**