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:
parent
6334f2cac1
commit
e42b13bcff
4 changed files with 68 additions and 7 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue