You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cycle ORM provides the ability to carry data over the specific class instances by using cycle/orm-promise-mapper
package with \Cycle\ORM\Reference\Promise objects for relations with lazy loading.
Installation
The preferred way to install this package is through Composer:
composer require cycle/orm-promise-mapper
Define the Entity
useCycle\Annotated\Annotation\Entity;
useCycle\Annotated\Annotation\Column;
useCycle\Annotated\Annotation\Relation\BelongsTo;
useCycle\Annotated\Annotation\Relation\HasMany;
useCycle\ORM\Reference\ReferenceInterface;
#[Entity]
class User
{
#[Column(type: 'primary')]
publicint$id;
#[HasMany(target: Post::class, load: 'eager')]
publicarray$posts;
#[HasMany(target: Tag::class, load: 'lazy')]
publicReferenceInterface|array$tags;
}
#[Entity]
class Post
{
// ...
#[BelongsTo(target: User::class, load: 'lazy')]
publicReferenceInterface|User$user;
#[BelongsTo(target: Tag::class, load: 'eager')]
publicTag$tag;
}
Fetching entity data
$user = $orm->getRepository('user')->findByPK(1);
// $user->posts contains an array because of eager loadingforeach ($user->postsas$post) {
// ...
}
// $user->tags contains Cycle\ORM\Reference\Promise object because of lazy loading$tags = $user->tags->fetch();
foreach ($tagsas$post) {
// ...
}
$post = $orm->getRepository('post')->findByPK(1);
// $post->user contains Cycle\ORM\Reference\Promise object because of lazy loading$userId = $post->user->fetch()->id;
// $post->tag contains Tag object because of eager loading$tagName = $post->tag->name;
License:
The MIT License (MIT). Please see LICENSE for more information.
Maintained by Spiral Scout.