Documentation

ManyToManyAdapter
in package
implements ArrayAccess, Iterator, AdapterInterface

This adapter allows the user to access Many to many relations inside the database as if it was an array with sorted data. This makes it easy to iterate over records or do actions on them. Please note that some of the actions performed on this records are very database intensive and are therefore to be used with care.

Interfaces, Classes and Traits

ArrayAccess
Iterator
AdapterInterface
An adapter is basically a simple block that contains receives and delivers data both to the user and the database. This turns it into a great tool to sanitize user data and prepare information from the DB in a way that it's user friendly.

Table of Contents

$children  : array<string|int, Model>
The data stored into the adapter. This helps caching the data and keeping a diff in case the data is modified.
$field  : ManyToManyField
The field the parent uses to refer to this element. This allows the app to identify the kind of data it can receive and what table it is referring.
$parent  : Model
The 'parent' record. This helps locating the children field that should be fetched when accessing the content of the adapter.
__construct()  : mixed
Creates a new adapter for fields that hold many to many data. This adapter allows you to access the related data for a 'parent' field on the related table.
commit()  : mixed
Settles the content inside the adapter. This method is usually called when the model is being stored. This means the data is considered final and the data inside the adapter is no longer out of sync with the database.
current()  : mixed
dbGetData()  : mixed
This method returns the data the adapter wants to store to the database. The DBMS controller should use this endpoint to collect the data it will store to the driver.
dbSetData()  : mixed
This method does nothing as this field has no direct data in the DBMS and therefore it just ignores whatever the database tries to input.
getBridgeRecordsQuery()  : mixed
getDependencies()  : mixed
getField()  : ManyToManyField
Returns the field that contains this data. This allows to query the table or target with ease.
getModel()  : Model
Returns the parent model for this adapter. This allows any application to trace what adapter this adapter belongs to.
getQuery()  : Query
Gets the query that fetches the current set of data located inside the database for this adapter. This allows the adapter to 'initialize' itself in case there was no data inside it when the user requested it.
isSynced()  : bool
Allows the adapter to tell the database driver whether the data inside this is synced (has not been modified) and should be stored to the database to avoid being lost.
key()  : mixed
next()  : mixed
offsetExists()  : mixed
offsetGet()  : mixed
offsetSet()  : mixed
offsetUnset()  : mixed
rewind()  : mixed
rollback()  : mixed
Resets the content inside the adapter. In case you don't want to keep the altered data and want to modify or read the original source data instead of the altered one.
store()  : mixed
toArray()  : mixed
usrGetData()  : mixed
Returns the data that is meant to reach the 'user space'. Objects here should be programmer friendly and can be objects if needed.
usrSetData()  : mixed
Defines the data inside this adapter. In case the user is trying to set this adapter as the source for itself, which can happen in case the user is reading the adapter and expecting himself to save it back this function will do nothing.
valid()  : mixed

Properties

$children

The data stored into the adapter. This helps caching the data and keeping a diff in case the data is modified.

private array<string|int, Model> $children

$field

The field the parent uses to refer to this element. This allows the app to identify the kind of data it can receive and what table it is referring.

private ManyToManyField $field

$parent

The 'parent' record. This helps locating the children field that should be fetched when accessing the content of the adapter.

private Model $parent

Methods

__construct()

Creates a new adapter for fields that hold many to many data. This adapter allows you to access the related data for a 'parent' field on the related table.

public __construct(ManyToManyField $field, Model $model[, void $data = null ]) : mixed

You can use this adapter to develop applications simultating that the data base can store arrays on relational stores.

Parameters
$field : ManyToManyField
$model : Model
$data : void = null
  • deprecated. Should no longer be used.
Return values
mixed

commit()

Settles the content inside the adapter. This method is usually called when the model is being stored. This means the data is considered final and the data inside the adapter is no longer out of sync with the database.

public commit() : mixed

In case the data is not stored inside the database you can use the commit function to do so, as this is called even if the adapter is in sync.

Return values
mixed

current()

public current() : mixed
Return values
mixed

dbGetData()

This method returns the data the adapter wants to store to the database. The DBMS controller should use this endpoint to collect the data it will store to the driver.

public dbGetData() : mixed
Return values
mixed

Data to be contained in the database.

dbSetData()

This method does nothing as this field has no direct data in the DBMS and therefore it just ignores whatever the database tries to input.

public dbSetData(mixed $data) : mixed
Parameters
$data : mixed
Return values
mixed

getBridgeRecordsQuery()

public getBridgeRecordsQuery() : mixed
Return values
mixed

getDependencies()

public getDependencies() : mixed
Return values
mixed

getModel()

Returns the parent model for this adapter. This allows any application to trace what adapter this adapter belongs to.

public getModel() : Model
Return values
Model

getQuery()

Gets the query that fetches the current set of data located inside the database for this adapter. This allows the adapter to 'initialize' itself in case there was no data inside it when the user requested it.

public getQuery() : Query
Return values
Query

isSynced()

Allows the adapter to tell the database driver whether the data inside this is synced (has not been modified) and should be stored to the database to avoid being lost.

public isSynced() : bool

If data considers itself non-DB friendly (like arrays / subrecords /etc) these should return false always and use the commit method to store the data.

Return values
bool

Indicates whether the data is already in sync. Returns false if it should be stored.

key()

public key() : mixed
Return values
mixed

next()

public next() : mixed
Return values
mixed

offsetExists()

public offsetExists(mixed $offset) : mixed
Parameters
$offset : mixed
Return values
mixed

offsetGet()

public offsetGet(mixed $offset) : mixed
Parameters
$offset : mixed
Return values
mixed

offsetSet()

public offsetSet(mixed $offset, mixed $value) : mixed
Parameters
$offset : mixed
$value : mixed
Return values
mixed

offsetUnset()

public offsetUnset(mixed $offset) : mixed
Parameters
$offset : mixed
Return values
mixed

rewind()

public rewind() : mixed
Return values
mixed

rollback()

Resets the content inside the adapter. In case you don't want to keep the altered data and want to modify or read the original source data instead of the altered one.

public rollback() : mixed
Return values
mixed

store()

public store() : mixed
Tags
deprecated

since version 0.1-dev

Return values
mixed

toArray()

public toArray() : mixed
Return values
mixed

usrGetData()

Returns the data that is meant to reach the 'user space'. Objects here should be programmer friendly and can be objects if needed.

public usrGetData() : mixed

You should avoid making verifications / parsing the data in this function, stuff you think should go here probably belongs in dbSetData()

Return values
mixed

Data to be delivered to the programmer

usrSetData()

Defines the data inside this adapter. In case the user is trying to set this adapter as the source for itself, which can happen in case the user is reading the adapter and expecting himself to save it back this function will do nothing.

public usrSetData(ManyToManyAdapter|array<string|int, Model$data) : mixed
Parameters
$data : ManyToManyAdapter|array<string|int, Model>
Tags
throws
PrivateException
Return values
mixed

valid()

public valid() : mixed
Return values
mixed

Search results