Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5636b52

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

File tree

Expand file treeCollapse file tree

1 file changed

+6
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+6
-5
lines changed

‎form/form_collections.rst

Copy file name to clipboardExpand all lines: form/form_collections.rst
+6-5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.