aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Entity/Entry.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-05-30 14:34:11 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-05-31 10:01:03 +0200
commit3be047456d6f91d8ef5404c9c7698e0d1f9a057d (patch)
tree6914fc02866751594b2d73387adb826bbce980f8 /src/Wallabag/CoreBundle/Entity/Entry.php
parent39ba51ca1af3085c3a7eb6dabdfae38c5034db1b (diff)
downloadwallabag-3be047456d6f91d8ef5404c9c7698e0d1f9a057d.tar.gz
wallabag-3be047456d6f91d8ef5404c9c7698e0d1f9a057d.tar.zst
wallabag-3be047456d6f91d8ef5404c9c7698e0d1f9a057d.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/Entry.php')
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 84981414..ceae78b0 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -178,7 +178,15 @@ class Entry
178 178
179 /** 179 /**
180 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) 180 * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
181 * @ORM\JoinTable 181 * @ORM\JoinTable(
182 * name="entry_tag",
183 * joinColumns={
184 * @ORM\JoinColumn(name="entry_id", referencedColumnName="id")
185 * },
186 * inverseJoinColumns={
187 * @ORM\JoinColumn(name="tag_id", referencedColumnName="id")
188 * }
189 * )
182 * 190 *
183 * @Groups({"entries_for_user", "export_all"}) 191 * @Groups({"entries_for_user", "export_all"})
184 */ 192 */
@@ -526,13 +534,18 @@ class Entry
526 } 534 }
527 } 535 }
528 536
529 $this->tags[] = $tag; 537 $this->tags->add($tag);
530 $tag->addEntry($this); 538 $tag->addEntry($this);
531 } 539 }
532 540
533 public function removeTag(Tag $tag) 541 public function removeTag(Tag $tag)
534 { 542 {
543 if (!$this->tags->contains($tag)) {
544 return;
545 }
546
535 $this->tags->removeElement($tag); 547 $this->tags->removeElement($tag);
548 $tag->removeEntry($this);
536 } 549 }
537 550
538 /** 551 /**