Documentation

Relation
in package

Class to handle all the relationship information of a Flex model.

Table of Contents

$class  : string
The name of the class of the related model
$externalKey  : string
Used in 'HasAndBelongs' relations It's the id of the other entity in the relation table
$instance  : null|object|array<string|int, mixed>
The instance of the related model/s This can be a class instance or an array in case of 'Has' and 'HasAndBelongs' relations.
$key  : string
The key to use in the relationship Belongs: will be the local field Has: will be the remote field HasAndBelongs: will be the local field name in the relation table
$loaded  : bool
Flag to check if the instance was loaded If a 'Has' or 'HasAndBelongs' relation is set to an empty array it will count as loaded, since it was just created.
$name  : string
Name of the relationship It will be indexed by that name in RelationManager
$relationTable  : string
Used in 'HasAndBelongs' relationships It's the name of the intermediate table
$removeOrphans  : bool
Whether to remove orphaned records or not after a 'Has' or a 'HasAndBelongs' relation records are updated.
$table  : string
The table name of the model
$tableAlias  : string
When using multiple references to the same table an alias is required.
$type  : string
The type of relationship Possible values: 'Belongs', 'Has' and 'HasAndBelongs'
$uniquePair  : string
Name of the unique pair of field names used in a 'HasAndBelongs' intermediate table.
__construct()  : mixed
add()  : Relation
Add an instance to the collection or do nothing if the current instance is not a collection
build()  : Relation
Set all the object's parameters via array input
getBelongInstance()  : null|object
Get the instance of a 'Belong' relation
getHasAndBelongsInstance()  : array<string|int, mixed>
Get the collection of related models
getHasInstance()  : array<string|int, mixed>
Get the collection of related models
getInstance()  : array<string|int, mixed>|object
Get the instance of this relation
initUnsetFields()  : Relation
Convenience method to set some default values if some required parameters are missing.
isCollection()  : bool
Check if the instance is a collection
isEmpty()  : bool
Check if a relation's instance is empty
isEmptyCollection()  : bool
Check if the collection is empty
setBelongInstance()  : Relation
Set the instance of a 'Belong' relation
setHasInstance()  : Relation
Set the instance of a 'Has' relation
setInstance()  : Relation
Set the instance of a relation
validateParams()  : Relation
Validate that all the required parameters for a relationship are set

Properties

$class

The name of the class of the related model

public string $class = 'Makiavelo\Flex\Flex'

$externalKey

Used in 'HasAndBelongs' relations It's the id of the other entity in the relation table

public string $externalKey

$instance

The instance of the related model/s This can be a class instance or an array in case of 'Has' and 'HasAndBelongs' relations.

public null|object|array<string|int, mixed> $instance = null

$key

The key to use in the relationship Belongs: will be the local field Has: will be the remote field HasAndBelongs: will be the local field name in the relation table

public string $key

$loaded

Flag to check if the instance was loaded If a 'Has' or 'HasAndBelongs' relation is set to an empty array it will count as loaded, since it was just created.

public bool $loaded = false

$name

Name of the relationship It will be indexed by that name in RelationManager

public string $name

$relationTable

Used in 'HasAndBelongs' relationships It's the name of the intermediate table

public string $relationTable

$removeOrphans

Whether to remove orphaned records or not after a 'Has' or a 'HasAndBelongs' relation records are updated.

public bool $removeOrphans = false

$table

The table name of the model

public string $table

$tableAlias

When using multiple references to the same table an alias is required.

public string $tableAlias

$type

The type of relationship Possible values: 'Belongs', 'Has' and 'HasAndBelongs'

public string $type = 'Belongs'

$uniquePair

Name of the unique pair of field names used in a 'HasAndBelongs' intermediate table.

public string $uniquePair

Methods

__construct()

public __construct([mixed $params = [] ]) : mixed
Parameters
$params : mixed = []
Return values
mixed

add()

Add an instance to the collection or do nothing if the current instance is not a collection

public add(mixed $model) : Relation
Parameters
$model : mixed
Return values
Relation

build()

Set all the object's parameters via array input

public build([array<string|int, mixed> $params = [] ]) : Relation
Parameters
$params : array<string|int, mixed> = []
Return values
Relation

getBelongInstance()

Get the instance of a 'Belong' relation

public getBelongInstance(Flex $model) : null|object
Parameters
$model : Flex
Return values
null|object

getHasAndBelongsInstance()

Get the collection of related models

public getHasAndBelongsInstance(Flex $model) : array<string|int, mixed>
Parameters
$model : Flex
Return values
array<string|int, mixed>

getHasInstance()

Get the collection of related models

public getHasInstance(Flex $model) : array<string|int, mixed>
Parameters
$model : Flex
Return values
array<string|int, mixed>

getInstance()

Get the instance of this relation

public getInstance(Flex $model) : array<string|int, mixed>|object
Parameters
$model : Flex
Return values
array<string|int, mixed>|object

initUnsetFields()

Convenience method to set some default values if some required parameters are missing.

public initUnsetFields() : Relation
Return values
Relation

isCollection()

Check if the instance is a collection

public isCollection() : bool
Return values
bool

isEmpty()

Check if a relation's instance is empty

public isEmpty() : bool
Return values
bool

isEmptyCollection()

Check if the collection is empty

public isEmptyCollection() : bool
Return values
bool

setBelongInstance()

Set the instance of a 'Belong' relation

public setBelongInstance(mixed $instance) : Relation
Parameters
$instance : mixed
Return values
Relation

setHasInstance()

Set the instance of a 'Has' relation

public setHasInstance(mixed $instance) : Relation
Parameters
$instance : mixed
Return values
Relation

setInstance()

Set the instance of a relation

public setInstance(mixed $instance) : Relation
Parameters
$instance : mixed
Return values
Relation

validateParams()

Validate that all the required parameters for a relationship are set

public validateParams(array<string|int, mixed> $params) : Relation
Parameters
$params : array<string|int, mixed>
Tags
throws
Exception
Return values
Relation

Search results