Cycle ORM use Doctrine/Collection in order to represent one to many relation types (such as hasMany, manyToMany).
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)
->select()
->with('posts')->limit(1)->fetchOne();
print_r($u->posts);
You can read more about the available collection API here.