interface Relation implements SS_List, Filterable, Sortable, Limitable (View source)

Abstract representation of a DB relation field, either saved or in memory

Below methods will be added in 5.x

Methods

public
T[]
toArray()

Returns all the items in the list in an array.

from  SS_List
public
array
toNestedArray()

Returns the contents of the list as an array of maps.

from  SS_List
public
add(mixed $item)

Adds an item to the list, making no guarantees about where it will appear.

from  SS_List
public
remove(mixed $item)

Removes an item from the list.

from  SS_List
public
T|null
first()

Returns the first item in the list.

from  SS_List
public
T|null
last()

Returns the last item in the list.

from  SS_List
public
Map
map(string $keyfield = 'ID', string $titlefield = 'Title')

Returns a map of a key field to a value field of all the items in the list.

from  SS_List
public
T|null
find(string $key, mixed $value)

Returns the first item in the list where the key field is equal to the value.

from  SS_List
public
array
column(string $colName = "ID")

Returns an array of a single field value for all items in the list.

from  SS_List
public
each($callback)

No description

from  SS_List
public
bool
canFilterBy(string $by)

Returns TRUE if the list can be filtered by a given field expression.

public
filter()

No description

public
filterAny()

No description

public
exclude()

No description

public
T>
filterByCallback(callable $callback)

Return a new instance of this list that excludes any items with these characteristics Filter this List by a callback function. The function will be passed each record of the List in turn, and must return true for the record to be included. Returns the filtered list.

public
T|null
byID(int $id)

Return the first item with the given ID

public
byIDs($ids)

No description

public
bool
canSortBy(string $by)

Returns TRUE if the list can be sorted by a field.

from  Sortable
public
sort()

No description

from  Sortable
public
reverse()

No description

from  Sortable
public
limit(int|null $length, int $offset = 0)

No description

public
setByIDList(int[] $idList)

Sets the ComponentSet to be the given ID list.

public
int[]
getIDList()

Returns an array with both the keys and values set to the IDs of the records in this list.

public
dbObject(string $fieldName)

Return the DBField object that represents the given field on the related class.

relation(mixed $relationName)

No description

forForeignID(mixed $id)

No description

string
dataClass()

No description

Details

T[] toArray()

Returns all the items in the list in an array.

Return Value

T[]

array toNestedArray()

Returns the contents of the list as an array of maps.

Return Value

array

add(mixed $item)

Adds an item to the list, making no guarantees about where it will appear.

Parameters

mixed $item

remove(mixed $item)

Removes an item from the list.

Parameters

mixed $item

T|null first()

Returns the first item in the list.

Return Value

T|null

T|null last()

Returns the last item in the list.

Return Value

T|null

Map map(string $keyfield = 'ID', string $titlefield = 'Title')

Returns a map of a key field to a value field of all the items in the list.

Parameters

string $keyfield
string $titlefield

Return Value

Map

T|null find(string $key, mixed $value)

Returns the first item in the list where the key field is equal to the value.

Parameters

string $key
mixed $value

Return Value

T|null

array column(string $colName = "ID")

Returns an array of a single field value for all items in the list.

Parameters

string $colName

Return Value

array

each($callback)

No description

Parameters

$callback

bool canFilterBy(string $by)

Returns TRUE if the list can be filtered by a given field expression.

Parameters

string $by

Return Value

bool

filter()

No description

filterAny()

No description

exclude()

No description

T> filterByCallback(callable $callback)

Return a new instance of this list that excludes any items with these characteristics Filter this List by a callback function. The function will be passed each record of the List in turn, and must return true for the record to be included. Returns the filtered list.

Parameters

callable $callback

Return Value

T>

Examples

$list = $list->filterByCallback(function($item, $list) { return $item->Age == 9; })

T|null byID(int $id)

Return the first item with the given ID

Parameters

int $id

Return Value

T|null

byIDs($ids)

No description

Parameters

$ids

bool canSortBy(string $by)

Returns TRUE if the list can be sorted by a field.

Parameters

string $by

Return Value

bool

sort()

No description

reverse()

No description

Limitable limit(int|null $length, int $offset = 0)

No description

Parameters

int|null $length
int $offset

Return Value

Limitable

setByIDList(int[] $idList)

Sets the ComponentSet to be the given ID list.

Records will be added and deleted as appropriate.

Parameters

int[] $idList

List of IDs.

int[] getIDList()

Returns an array with both the keys and values set to the IDs of the records in this list.

Does not return the IDs for unsaved DataObjects

Return Value

int[]

DBField dbObject(string $fieldName)

Return the DBField object that represents the given field on the related class.

Parameters

string $fieldName

Name of the field

Return Value

DBField

The field as a DBField object

Relation relation(mixed $relationName)

No description

Parameters

mixed $relationName

Return Value

Relation

Relation forForeignID(mixed $id)

No description

Parameters

mixed $id

Return Value

Relation

string dataClass()

No description

Return Value

string