Skip to content

Explaining the "one-to-many" case more explicitly #9259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions form/form_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -561,15 +561,19 @@ you will learn about next!).

// src/AppBundle/Entity/Task.php

// ...
public function addTag(Tag $tag)
{
// for a many-to-many association:
$tag->addTask($this);

// for a many-to-one association:
$tag->setTask($this);

$this->tags->add($tag);
}

Inside ``Tag``, just make sure you have an ``addTask()`` method::
If you're going for ``addTask()``, just make sure you have an appropriate method
that looks something like this::

// src/AppBundle/Entity/Tag.php

Expand All @@ -581,9 +585,6 @@ you will learn about next!).
}
}

If you have a one-to-many relationship, then the workaround is similar,
except that you can simply call ``setTask()`` from inside ``addTag()``.

.. _form-collections-remove:

Allowing Tags to be Removed
Expand Down