Menu

## Join extends Ext
in package

Join.php : 61

Join table class for DataTables Editor.

The Join class can be used with Editor->join() to allow Editor to obtain joined information from the database.

For an overview of how Join tables work, please refer to the Editor manual as it is useful to understand how this class represents the links between tables, before fully getting to grips with it's API.

##### Tags

example

  Join the parent table (the one specified in the Editor->table() method) with the table access, with a link table user__access, which allows multiple properties to be found for each row in the parent table.

        Join::inst( 'access', 'array' )
            ->link( 'users.id', 'user_access.user_id' )
            ->link( 'access.id', 'user_access.access_id' )
            ->field(
                Field::inst( 'id' )->validator( 'Validate::required' ),
                Field::inst( 'name' )
            )

  @example Single row join - here we join the parent table with a single row in the child table, without an intermediate link table. In this case the child table is called extra and the two fields give the columns that Editor will read from that table.

          Join::inst( 'extra', 'object' )
              ->link( 'user.id', 'extra.user_id' )
              ->field(
                  Field::inst( 'comments' ),
                  Field::inst( 'review' )
              )

### Table of Contents

__construct() : mixed
  Join instance constructor.
aliasParentTable() : mixed
  Get / set parent table alias.
create() : mixed
  Create a row.
data() : mixed
  Get data
field() : mixed
  Get / set field instances.
fields() : mixed
  Get / set field instances.
get() : mixed
  Get / set get attribute.
inst() : Editor|Field|Join|Upload
  Static method to instantiate a new instance of a class (shorthand of 'instantiate').
instantiate() : Editor|Field|Join|Upload
  Static method to instantiate a new instance of a class.
join() : mixed
  Get / set join properties.
leftJoin() : self
  Set up a left join operation for the Mjoined data
link() : Join
  Create a join link between two tables. The order of the fields does not matter, but each field must contain the table name as well as the field name.
name() : mixed
  Get / set name.
order() : Join
  Specify the property that the data will be sorted by.
remove() : mixed
  Delete rows
set() : mixed
  Get / set set attribute.
table() : mixed
  Get / set join table name.
type() : mixed
  Get / set the join type.
update() : mixed
  Update a row.
validator() : self
  Set a validator for the array of data (not on a field basis)
where() : mixed
  Where condition to add to the query used to get data from the database.
whereSet() : mixed
  Get / set if the WHERE conditions should be included in the create and edit actions.
_getSet() : mixed
  Common getter / setter function for DataTables classes.
_propExists() : bool
  Determine if a property is available in a data set (allowing `null` to be a valid value)
_readProp() : mixed
  Read a value from a data structure, using Javascript dotted object notation. This is the inverse of the `_writeProp` method and provides the same support, matching DataTables' ability to read nested JSON data objects.
_writeProp() : mixed
  Write the field's value to an array structure, using Javascript dotted object notation to indicate JSON data structure. For example `name.first` gives the data structure: `name: { first: ... }`. This matches DataTables own ability to do this on the client-side, although this doesn't implement implement quite such a complex structure (no array / function support).

### Methods

#### __construct()

Join.php : 72

Join instance constructor.

`public __construct([mixed $table = null ][, string $type = 'object' ]) : mixed`

@param string $table Table name to get the joined data from.

##### Parameters

$table : mixed = null
$type : string = 'object'

  Work with a single result ('object') or an array of results ('array') for the join.

##### Return values

mixed —

#### aliasParentTable()

Join.php : 153

Get / set parent table alias.

`public aliasParentTable([string $_ = null ]) : mixed`

When working with a self referencing table (i.e. a column in the table contains a primary key value from its own table) it can be useful to set an alias on the parent table's name, allowing a self referencing Join. For example:

    SELECT p2.publisher
    FROM   publisher as p2
    JOIN   publisher on (publisher.idPublisher = p2.idPublisher)

Where, in this case, `publisher` is the table that is used by the Editor instance, and you want to use `Join` to link back to the table (resolving a name for example). This method allows that alias to be set. Fields can then use standard SQL notation to select a field, for example `p2.publisher` or `publisher.publisher`.

##### Parameters

$_ : string = null

  Table alias to use @return string|self Table alias set (which is null by default), or self if used as a setter.

##### Return values

mixed —

#### create()

Join.php : 658

Create a row.

`public create(mixed $editor, int $parentId, mixed $data) : mixed`

@param Editor $editor Host Editor instance

##### Parameters

$editor : mixed
$parentId : int

  Parent row's primary key value @param string[] $data Data to be set for the join @internal

$data : mixed

##### Return values

mixed —

#### data()

Join.php : 481

Get data

`public data(mixed $editor, array<string|int, string> &$data, mixed &$options) : mixed`

@param Editor $editor Host Editor instance

##### Parameters

$editor : mixed
$data : array<string|int, string>

  Data from the parent table's get and were we need to add out output. @param array $options options array for fields @internal

$options : mixed

##### Return values

mixed —

#### field()

Join.php : 170

Get / set field instances.

`public field([mixed $_ = null ]) : mixed`

The list of fields designates which columns in the table that will be read from the joined table.

##### Parameters

$_ : mixed = null

##### Return values

mixed —

#### fields()

Join.php : 191

Get / set field instances.

`public fields([mixed $_ = null ]) : mixed`

An alias of field, for convenience.

##### Parameters

$_ : mixed = null

##### Return values

mixed —

#### get()

Join.php : 209

Get / set get attribute.

`public get([bool $_ = null ]) : mixed`

When set to false no read operations will occur on the join tables.

##### Parameters

$_ : bool = null

  Value @return boolean|self Name

##### Return values

mixed —

#### inst()

Ext.php : 51

Static method to instantiate a new instance of a class (shorthand of 'instantiate').

`public static inst() : Editor|Field|Join|Upload`

This method performs exactly the same actions as the 'instantiate' static method, but is simply shorter and easier to type!

##### Return values

Editor|Field|Join|Upload —

class @static

#### instantiate()

Ext.php : 32

Static method to instantiate a new instance of a class.

`public static instantiate() : Editor|Field|Join|Upload`

A factory method that will create a new instance of the class that has extended 'Ext'. This allows classes to be instantiated and then chained - which otherwise isn't available until PHP 5.4. If using PHP 5.4 or later, simply create a 'new' instance of the target class and chain methods as normal.

##### Return values

Editor|Field|Join|Upload —

Instantiated class @static

#### join()

Join.php : 242

Get / set join properties.

`public join([string|array<string|int, string> $parent = null ][, mixed $child = null ][, mixed $table = null ]) : mixed`

Define how the SQL will be performed, on what columns. There are basically two types of join that are supported by Editor here, a direct foreign key reference in the join table to the parent table's primary key, or a link table that contains just primary keys for the parent and child tables (this approach is usually used with a Join->type() of 'array' since you can often have multiple links between the two tables, while a direct foreign key reference will typically use a type of 'object' (i.e. a single entry).

##### Parameters

$parent : string|array<string|int, string> = null

  Parent table's primary key names. If used with a link table (i.e. third parameter to this method is given, then an array should be used, with the first element being the pkey's name in the parent table, and the second element being the key's name in the link table. @param string|string[] $child Child table's primary key names. If used with a link table (i.e. third parameter to this method is given, then an array should be used, with the first element being the pkey's name in the child table, and the second element being the key's name in the link table. @param string $table Join table name, if using a link table @returns Join This for chaining @deprecated 1.5 Please use the Join->link() method rather than this method now.

$child : mixed = null
$table : mixed = null

##### Return values

mixed —

#### leftJoin()

Join.php : 264

Set up a left join operation for the Mjoined data

`public leftJoin(string $table, string $field1, string $operator, string $field2) : self`

##### Parameters

$table : string

  to get the information from

$field1 : string

  the first field to get the information from

$operator : string

  the operation to perform on the two fields

$field2 : string

  the second field to get the information from

##### Return values

self —

#### link()

Join.php : 296

Create a join link between two tables. The order of the fields does not matter, but each field must contain the table name as well as the field name.

`public link(string $field1, string $field2) : Join`

This method can be called a maximum of two times for an Mjoin instance:

- First time, creates a link between the Editor host table and a join table
- Second time creates the links required for a link table.

Please refer to the Editor Mjoin documentation for further details: https://editor.datatables.net/manual/php

##### Parameters

$field1 : string

  Table and field name

$field2 : string

  Table and field name

##### Tags

throws
  Exception

  Link limitations

##### Return values

Join —

Self for chaining

#### name()

Join.php : 338

Get / set name.

`public name([string $_ = null ]) : mixed`

The `name` of the Join is the JSON property key that is used when 'getting' the data, and the HTTP property key (in a JSON style) when 'setting' data. Typically the name of the db table will be used here, but this method allows that to be overridden.

##### Parameters

$_ : string = null

  Field name @return String|self Name

##### Return values

mixed —

#### order()

Join.php : 319

Specify the property that the data will be sorted by.

`public order([mixed $_ = null ]) : Join`

##### Parameters

$_ : mixed = null

##### Return values

Join —

Self for chaining

#### remove()

Join.php : 722

Delete rows

`public remove(mixed $editor, array<string|int, int> $ids) : mixed`

@param Editor $editor Host Editor instance

##### Parameters

$editor : mixed
$ids : array<string|int, int>

  Parent row IDs to delete @internal

##### Return values

mixed —

#### set()

Join.php : 353

Get / set set attribute.

`public set([bool $_ = null ]) : mixed`

When set to false no write operations will occur on the join tables. This can be useful when you want to display information which is joined, but want to only perform write operations on the parent table.

##### Parameters

$_ : bool = null

  Value @return boolean|self Name

##### Return values

mixed —

#### table()

Join.php : 369

Get / set join table name.

`public table([string $_ = null ]) : mixed`

Please note that this will also set the Join->name() used by the Join as well. This is for convenience as the JSON output / HTTP input will typically use the same name as the database name. If you want to set a custom name, the Join->name() method must be called after this one.

##### Parameters

$_ : string = null

  Name of the table to read the join data from @return String|self Name of the join table, or self if used as a setter.

##### Return values

mixed —

#### type()

Join.php : 389

Get / set the join type.

`public type([string $_ = null ]) : mixed`

The join type allows the data that is returned from the join to be given as an array (i.e. working with multiple possibly results for each record from the parent table), or as an object (i.e. working which one and only one result for each record form the parent table).

##### Parameters

$_ : string = null

  Join type ('object') or an array of results ('array') for the join. @return String|self Join type, or self if used as a setter.

##### Return values

mixed —

#### update()

Join.php : 691

Update a row.

`public update(mixed $editor, int $parentId, mixed $data) : mixed`

@param Editor $editor Host Editor instance

##### Parameters

$editor : mixed
$parentId : int

  Parent row's primary key value @param string[] $data Data to be set for the join @internal

$data : mixed

##### Return values

mixed —

#### validator()

Join.php : 403

Set a validator for the array of data (not on a field basis)

`public validator(string $fieldName, callable $fn) : self`

##### Parameters

$fieldName : string

  Name of the field that any error should be shown against on the client-side

$fn : callable

  Callback function for validation

##### Return values

self —

Chainable

#### where()

Join.php : 428

Where condition to add to the query used to get data from the database.

`public where([string|callable $key = null ][, mixed $value = null ][, mixed $op = '=' ]) : mixed`

Note that this is applied to the child table.

Can be used in two different ways:

- Simple case: `where( field, value, operator )`
- Complex: `where( fn )`

##### Parameters

$key : string|callable = null

  Single field name or a closure function @param string|string[] $value Single field value, or an array of values. @param string $op Condition operator: <, >, = etc @return string[]|self Where condition array, or self if used as a setter.

$value : mixed = null
$op : mixed = '='

##### Return values

mixed —

#### whereSet()

Join.php : 462

Get / set if the WHERE conditions should be included in the create and edit actions.

`public whereSet([bool $_ = null ]) : mixed`

This means that the fields which have been used as part of the 'get' WHERE condition (using the `where()` method) will be set as the values given.

This is default false (i.e. they are not included).

##### Parameters

$_ : bool = null

  Include (`true`), or not (`false`) @return boolean Current value

##### Return values

mixed —

#### _getSet()

Ext.php : 75

Common getter / setter function for DataTables classes.

`protected _getSet(mixed &$prop, mixed $val[, mixed $array = false ]) : mixed`

This getter / setter method makes building getter / setting methods easier, by abstracting everything to a single function call.

##### Parameters

$prop : mixed

  The property to set @param mixed $val The value to set - if given as null, then we assume that the function is being used as a getter. @param boolean $array Treat the target property as an array or not (default false). If used as an array, then values passed in are added to the $prop array. @return self|mixed Class instance if setting (allowing chaining), or the value requested if getting.

$val : mixed
$array : mixed = false

##### Return values

mixed —

#### _propExists()

Ext.php : 105

Determine if a property is available in a data set (allowing `null` to be a valid value)

`protected _propExists(string $name, array<string|int, mixed> $data) : bool`

##### Parameters

$name : string

  Javascript dotted object name to write to

$data : array<string|int, mixed>

  Data source array to read from

##### Tags

private

##### Return values

bool —

true if present, false otherwise

#### _readProp()

Ext.php : 142

Read a value from a data structure, using Javascript dotted object notation. This is the inverse of the `_writeProp` method and provides the same support, matching DataTables' ability to read nested JSON data objects.

`protected _readProp(string $name, array<string|int, mixed> $data) : mixed`

##### Parameters

$name : string

  Javascript dotted object name to write to

$data : array<string|int, mixed>

  Data source array to read from

##### Tags

private

##### Return values

mixed —

The read value, or null if no value found.

#### _writeProp()

Ext.php : 186

Write the field's value to an array structure, using Javascript dotted object notation to indicate JSON data structure. For example `name.first` gives the data structure: `name: { first: ... }`. This matches DataTables own ability to do this on the client-side, although this doesn't implement implement quite such a complex structure (no array / function support).

`protected _writeProp(array<string|int, mixed> &$out, string $name, mixed $value) : mixed`

##### Parameters

$out : array<string|int, mixed>

  Array to write the data to

$name : string

  Javascript dotted object name to write to

$value : mixed

  Value to write

##### Tags

throws
  Exception

  Information about duplicate properties

private

##### Return values

mixed —

## Search results