aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Entity/Tag.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-05-30 14:34:11 +0200
committerThomas Citharel <tcit@tcit.fr>2016-06-23 09:15:50 +0200
commite42b13bcff41161ecdb4322dce1ef98a401482ca (patch)
treefcec3ed14bcb9d2d0ea4d07647dbcb61c9aae9fe /src/Wallabag/CoreBundle/Entity/Tag.php
parent6334f2cac16158a0ea4a8e540ace17550085942b (diff)
downloadwallabag-e42b13bcff41161ecdb4322dce1ef98a401482ca.tar.gz
wallabag-e42b13bcff41161ecdb4322dce1ef98a401482ca.tar.zst
wallabag-e42b13bcff41161ecdb4322dce1ef98a401482ca.zip
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
Diffstat (limited to 'src/Wallabag/CoreBundle/Entity/Tag.php')
-rw-r--r--src/Wallabag/CoreBundle/Entity/Tag.php23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php
index b4adbbd3..4b480ff1 100644
--- a/src/Wallabag/CoreBundle/Entity/Tag.php
+++ b/src/Wallabag/CoreBundle/Entity/Tag.php
@@ -98,9 +98,30 @@ class Tag
98 return $this->slug; 98 return $this->slug;
99 } 99 }
100 100
101 /**
102 * @param Entry $entry
103 */
101 public function addEntry(Entry $entry) 104 public function addEntry(Entry $entry)
102 { 105 {
103 $this->entries[] = $entry; 106 if ($this->entries->contains($entry)) {
107 return;
108 }
109
110 $this->entries->add($entry);
111 $entry->addTag($this);
112 }
113
114 /**
115 * @param Entry $entry
116 */
117 public function removeEntry(Entry $entry)
118 {
119 if (!$this->entries->contains($entry)) {
120 return;
121 }
122
123 $this->entries->removeElement($entry);
124 $entry->removeTag($this);
104 } 125 }
105 126
106 public function hasEntry($entry) 127 public function hasEntry($entry)