Skip to content

Commit e973497

Browse files
committed
minor #9259 Explaining the "one-to-many" case more explicitly (ThomasLandauer)
This PR was squashed before being merged into the 2.7 branch (closes #9259). Discussion ---------- Explaining the "one-to-many" case more explicitly Please double-check: I'm not certain if "For a many-to-many relationship:" (line 574) is correct! Commits ------- 5636b52 Explaining the "one-to-many" case more explicitly
2 parents 0d079be + 5636b52 commit e973497

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)