tflori/orm

just another orm...

View the Project on GitHub tflori/orm

Build Status Test Coverage Maintainability Latest Stable Version Total Downloads

» API Reference » ORM\Entity\Relations

ORM\Entity\Relations

Table of Contents

Abstract

Methods

ORM\Entity\Relations::addRelated

public function addRelated(string $relation, \ORM\Entity[] $entities): mixed
Add relations for $relation to $entities

This method is only for many-to-many relations.

This method does not take care about already existing relations and will fail hard.

Returns mixed  
Parameters
Parameter Type Description
$relation string  
$entities ORM\Entity[]  

ORM\Entity\Relations::addRelated

↑ top


ORM\Entity\Relations::deleteRelated

public function deleteRelated(string $relation, \ORM\Entity[] $entities): mixed
Delete relations for $relation to $entities

This method is only for many-to-many relations.

Returns mixed  
Parameters
Parameter Type Description
$relation string  
$entities ORM\Entity[]  

ORM\Entity\Relations::deleteRelated

↑ top


ORM\Entity\Relations::fetch

public function fetch(
    string $relation, 
    bool $getAll = false, 
): \ORM\Entity|\ORM\Entity[]|\ORM\EntityFetcher

For relations with cardinality many it returns an EntityFetcher. Otherwise it returns the entity.

It will throw an error for non owner when the key is incomplete.

Returns ORM\Entity|ORM\Entity[]|ORM\EntityFetcher  
Parameters
Parameter Type Description
$relation string The relation to fetch
$getAll bool  

ORM\Entity\Relations::fetch

↑ top


ORM\Entity\Relations::getRelated

public function getRelated(string $relation, bool $refresh = false): mixed

The difference between getRelated and fetch is that getRelated stores the fetched entities. To refresh set $refresh to true.

Returns mixed  
Parameters
Parameter Type Description
$relation string  
$refresh bool  

ORM\Entity\Relations::getRelated

↑ top


ORM\Entity\Relations::getRelation

public static function getRelation(string $name): \ORM\Relation
Get the definition for $relation

It normalize the short definition form and create a Relation object from it.

Static   This method is static.
Returns ORM\Relation  
Throws ORM\Exception\UndefinedRelation  
Parameters
Parameter Type Description
$name string  

ORM\Entity\Relations::getRelation

↑ top


ORM\Entity\Relations::hasLoaded

public function hasLoaded(string $relation): bool
Check if $relation got loaded already
Returns bool  
Parameters
Parameter Type Description
$relation string  

ORM\Entity\Relations::hasLoaded

↑ top


ORM\Entity\Relations::load

public function load(string $relation): $this

Nested relations can be loaded by separating them by “.” for example load all articles with comments from a user ($this): $user->load('articles.comments').

Returns $this  
Parameters
Parameter Type Description
$relation string  

ORM\Entity\Relations::load

↑ top


ORM\Entity\Relations::resetRelated

public function resetRelated(null $relation = null): mixed
Resets all loaded relations or $relation

Helpful to reduce the size of serializations of the object (for caching, or toArray method etc.)

Returns mixed  
Parameters
Parameter Type Description
$relation null  

ORM\Entity\Relations::resetRelated

↑ top


ORM\Entity\Relations::setRelated

public function setRelated(string $relation, \ORM\Entity $entity = null): mixed
Set $relation to $entity

This method is only for the owner of a relation.

Returns mixed  
Parameters
Parameter Type Description
$relation string  
$entity ORM\Entity  

ORM\Entity\Relations::setRelated

↑ top