File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -561,15 +561,19 @@ you will learn about next!).
561
561
562
562
// src/AppBundle/Entity/Task.php
563
563
564
- // ...
565
564
public function addTag(Tag $tag)
566
565
{
566
+ // for a many-to-many association:
567
567
$tag->addTask($this);
568
568
569
+ // for a many-to-one association:
570
+ $tag->setTask($this);
571
+
569
572
$this->tags->add($tag);
570
573
}
571
574
572
- Inside ``Tag ``, just make sure you have an ``addTask() `` method::
575
+ If you're going for ``addTask() ``, just make sure you have an appropriate method
576
+ that looks something like this::
573
577
574
578
// src/AppBundle/Entity/Tag.php
575
579
@@ -581,9 +585,6 @@ you will learn about next!).
581
585
}
582
586
}
583
587
584
- If you have a one-to-many relationship, then the workaround is similar,
585
- except that you can simply call ``setTask() `` from inside ``addTag() ``.
586
-
587
588
.. _form-collections-remove :
588
589
589
590
Allowing Tags to be Removed
You can’t perform that action at this time.
0 commit comments