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!).
561561
562562 // src/AppBundle/Entity/Task.php
563563
564- // ...
565564 public function addTag(Tag $tag)
566565 {
566+ // for a many-to-many association:
567567 $tag->addTask($this);
568568
569+ // for a many-to-one association:
570+ $tag->setTask($this);
571+
569572 $this->tags->add($tag);
570573 }
571574
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::
573577
574578 // src/AppBundle/Entity/Tag.php
575579
@@ -581,9 +585,6 @@ you will learn about next!).
581585 }
582586 }
583587
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-
587588.. _form-collections-remove :
588589
589590Allowing Tags to be Removed
You can’t perform that action at this time.
0 commit comments