Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 1.02 KB

collections.md

File metadata and controls

37 lines (28 loc) · 1.02 KB

Collections

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

See cycle/orm#24

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:

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

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

    public function __construct()
    {
        $this->address = new ArrayCollection();
    }
}

The collection property will be set automatically on the selection:

$users = $orm->getRepository(User::class)
    ->select()
    ->with('posts')->limit(1)->fetchOne();

print_r($u->posts);

Collection API

You can read more about the available collection API here.