Cycle ORM use Doctrine/Collection in order to represent one to many relation types (such as hasMany, manyToMany).


Accessing Collection

The ORM will automatically instantiate a collection instance for your relations, however, you are still required to initiate empty collections in your constructor to use newly created entities:

use Doctrine\Common\Collections\ArrayCollection;

/** @Entity */
class User
    // ...

    /** @HasMany(target = "Post") */
    public $posts;

    public function __construct()
        $this->posts = new ArrayCollection();

The collection property will be set automatically on the selection:

$users = $orm->getRepository(User::class)


Collection API

You can read more about the available collection API here.

Edit this page