Relationship
Allow to automagically save relationship
- Full name:
\Zemit\Mvc\Model\Traits\Relationship
Properties
keepMissingRelated
private array $keepMissingRelated
relationshipContext
private string $relationshipContext
dirtyRelated
protected $dirtyRelated
Methods
appendMessage
public appendMessage(\Phalcon\Messages\MessageInterface $message): \Phalcon\Mvc\ModelInterface
- This method is abstract.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | \Phalcon\Messages\MessageInterface |
setKeepMissingRelated
Set the missing related configuration list
public setKeepMissingRelated(array $keepMissingRelated): void
Parameters:
Parameter | Type | Description |
---|---|---|
$keepMissingRelated | array |
getKeepMissingRelated
Return the missing related configuration list
public getKeepMissingRelated(): array
getKeepMissingRelatedAlias
Return the keepMissing configuration for a specific relationship alias
public getKeepMissingRelatedAlias(string $alias): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$alias | string |
setKeepMissingRelatedAlias
Set the keepMissing configuration for a specific relationship alias
public setKeepMissingRelatedAlias(string $alias, bool $keepMissing): void
Parameters:
Parameter | Type | Description |
---|---|---|
$alias | string | |
$keepMissing | bool |
getRelationshipContext
Get the current relationship context
public getRelationshipContext(): string
setRelationshipContext
Set the current relationship context
public setRelationshipContext(string $context): void
Parameters:
Parameter | Type | Description |
---|---|---|
$context | string |
getDirtyRelated
Return the dirtyRelated entities
public getDirtyRelated(): array
setDirtyRelated
Set the dirtyRelated entities
public setDirtyRelated(array $dirtyRelated): void
Parameters:
Parameter | Type | Description |
---|---|---|
$dirtyRelated | array |
getDirtyRelatedAlias
Return the dirtyRelated entities
public getDirtyRelatedAlias(string $alias): mixed
Parameters:
Parameter | Type | Description |
---|---|---|
$alias | string |
setDirtyRelatedAlias
Return the dirtyRelated entities
public setDirtyRelatedAlias(string $alias, mixed $value): void
Parameters:
Parameter | Type | Description |
---|---|---|
$alias | string | |
$value | mixed |
hasDirtyRelated
Check whether the current entity has dirty related or not
public hasDirtyRelated(): bool
hasDirtyRelatedAlias
Check whether the current entity has dirty related or not
public hasDirtyRelatedAlias(string $alias): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$alias | string |
assign
{@inheritDoc}
public assign(array $data, mixed $whiteList = null, mixed $dataColumnMap = null): \Phalcon\Mvc\ModelInterface
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array | |
$whiteList | mixed | |
$dataColumnMap | mixed |
Throws:
assignRelated
Assign related
public assignRelated(array $data, array|null $whiteList = null, array|null $dataColumnMap = null): \Phalcon\Mvc\ModelInterface
Single [alias => new Alias()] // create new alias
Many [alias => [new Alias()]] // create new alias [alias => [1, 2, 3, 4]] // append / merge 1, 2, 3, 4 [alias => [false, 1, 2, 4]]; // delete 3
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array | |
$whiteList | **array | null** |
$dataColumnMap | **array | null** |
Throws:
preSaveRelatedRecords
Saves related records that must be stored prior to save the master record Refactored based on the native cphalcon version, so we can support : - combined keys on relationship definition - relationship context within the model messages based on the alias definition
protected preSaveRelatedRecords(\Phalcon\Db\Adapter\AdapterInterface $connection, mixed $related, \Phalcon\Support\Collection\CollectionInterface $visited): bool
Parameters:
Parameter | Type | Description |
---|---|---|
$connection | \Phalcon\Db\Adapter\AdapterInterface | |
$related | mixed | |
$visited | \Phalcon\Support\Collection\CollectionInterface |
Throws:
postSaveRelatedRecords
NOTE: we need this, this behaviour only happens: - in many to many nodes Fix uniqueness on combined keys in node entities, and possibly more.
protected postSaveRelatedRecords(\Phalcon\Db\Adapter\AdapterInterface $connection, mixed $related, \Phalcon\Support\Collection\CollectionInterface $visited): bool
..
Parameters:
Parameter | Type | Description |
---|---|---|
$connection | \Phalcon\Db\Adapter\AdapterInterface | |
$related | mixed | |
$visited | \Phalcon\Support\Collection\CollectionInterface |
Throws:
See Also:
- https://forum.phalconphp.com/discussion/2190/many-to-many-expected-behaviour - * http://stackoverflow.com/questions/23374858/update-a-records-n-n-relationships - * https://github.com/phalcon/cphalcon/issues/2871 -
postSaveRelatedRecordsAfter
public postSaveRelatedRecordsAfter(\Phalcon\Mvc\Model\RelationInterface $relation, mixed $relatedRecords, \Phalcon\Support\Collection\CollectionInterface $visited): ?bool
Parameters:
Parameter | Type | Description |
---|---|---|
$relation | \Phalcon\Mvc\Model\RelationInterface | |
$relatedRecords | mixed | |
$visited | \Phalcon\Support\Collection\CollectionInterface |
postSaveRelatedThroughAfter
public postSaveRelatedThroughAfter(\Phalcon\Mvc\Model\RelationInterface $relation, mixed $relatedRecords, \Phalcon\Support\Collection\CollectionInterface $visited): ?bool
Parameters:
Parameter | Type | Description |
---|---|---|
$relation | \Phalcon\Mvc\Model\RelationInterface | |
$relatedRecords | mixed | |
$visited | \Phalcon\Support\Collection\CollectionInterface |
getEntityFromData
Get an entity from data
public getEntityFromData(array $data, array $configuration = []): \Phalcon\Mvc\ModelInterface
Parameters:
Parameter | Type | Description |
---|---|---|
$data | array | |
$configuration | array |
appendMessages
public appendMessages(array $messages = [], ?string $context = null, ?int $index = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$messages | array | |
$context | ?string | |
$index | ?int |
appendMessagesFromRecord
Appends messages from a record to the current messages container.
public appendMessagesFromRecord(\Phalcon\Mvc\ModelInterface|null $record = null, string|null $context = null, int|null $index = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$record | **\Phalcon\Mvc\ModelInterface | null** |
$context | **string | null** |
$index | **int | null** |
appendMessagesFromResultset
Append messages from a resultset to the current message container.
public appendMessagesFromResultset(\Phalcon\Mvc\Model\ResultsetInterface|null $resultset = null, string|null $context = null, int|null $index = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$resultset | **\Phalcon\Mvc\Model\ResultsetInterface | null** |
$context | **string | null** |
$index | **int | null** |
appendMessagesFromRecordList
Appends messages from a record list to the current message container.
public appendMessagesFromRecordList(iterable|null $recordList = null, string|null $context = null, int|null $index = null): void
Parameters:
Parameter | Type | Description |
---|---|---|
$recordList | **iterable | null** |
$context | **string | null** |
$index | **int | null** |
rebuildMessageContext
Rebuilds the message context.
public rebuildMessageContext(\Phalcon\Messages\Message $message, string|null $context = null): string
This method appends the given context to the previous context stored in the message metadata. If there is no previous context, only the given context is returned.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | \Phalcon\Messages\Message | The message object whose context needs to be rebuilt. |
$context | **string | null** |
Return Value:
The rebuilt context
rebuildMessageIndex
Rebuilds the message index.
public rebuildMessageIndex(\Phalcon\Messages\Message $message, int|null $index = null): string
This method constructs the new message index based on the provided $index argument and the previous index stored in the message's metadata. It returns the new index as a string.
Parameters:
Parameter | Type | Description |
---|---|---|
$message | \Phalcon\Messages\Message | The message object for which the index is being rebuilt. |
$index | **int | null** |
Return Value:
The new index as a string
relatedToArray
Retrieves the related records as an array.
public relatedToArray(array|null $columns = null, bool $useGetter = true): array
If $columns is provided, only the specified columns will be included in the array. If $useGetter is set to true, it will use the getter methods of the related records.
Parameters:
Parameter | Type | Description |
---|---|---|
$columns | **array | null** |
$useGetter | bool | (optional) Whether to use getter methods of the related records (default: true) |
Return Value:
The related records as an array
getRelated
Overriding default phalcon getRelated in order to fix an important issue where the related record is being stored into the "related" property and then passed from the collectRelatedToSave and is mistakenly saved without the user consent
public getRelated(string $alias, $arguments = null): false|int|\Phalcon\Mvc\Model\Resultset\Simple
Parameters:
Parameter | Type | Description |
---|---|---|
$alias | string | |
$arguments | **** |
Throws:
toArray
{@inheritDoc}
public toArray(mixed $columns = null, mixed $useGetter = true): array
Parameters:
Parameter | Type | Description |
---|---|---|
$columns | mixed | |
$useGetter | mixed |