PHPackages                             nassau/relation-collection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. nassau/relation-collection

ActiveLibrary[Database &amp; ORM](/categories/database)

nassau/relation-collection
==========================

Doctrine Collection automatically sets the owner when adding an item

v1.0(10y ago)125.4k1MITPHP

Since Jul 3Pushed 10y ago1 watchersCompare

[ Source](https://github.com/mlebkowski/relation-collection)[ Packagist](https://packagist.org/packages/nassau/relation-collection)[ RSS](/packages/nassau-relation-collection/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

Doctrine Relation Collection
============================

[](#doctrine-relation-collection)

This Collection knows about their parent and sets it on an item when adding, .i.e:

```
$collection = $foo->getBars();
$collection->add($bar); // behind the scenes: $bar->setFoo($foo);

```

This way you can manage this relation via Symfony Forms without the ugly `by_reference` and `addBar()/removeBar()` methods.

Requirements
------------

[](#requirements)

You need to either:

- wrap an initialized `PersistentCollection` with `PeristentAssociationRelationCollection` — works out of the box
- use `RelationCollection` and tell it how to set the owner of an object using a closure. the former does this automatically basing on mapping information retrieved from `PersistentCollection`

Why?
----

[](#why)

Because I don’t want to write adders/removers boilerplate for every relation. And also because of reasons.

Example usage
-------------

[](#example-usage)

### With existing doctrine relations

[](#with-existing-doctrine-relations)

```
