Skip to content

Commit 5636b52

Browse files
ThomasLandauerjaviereguiluz
authored andcommitted
Explaining the "one-to-many" case more explicitly
1 parent 993c71e commit 5636b52

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

form/form_collections.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff 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

589590
Allowing Tags to be Removed

0 commit comments

Comments
 (0)