Class Table
A representation of a database table.
-
ICanBoogie\Object
-
┗
ICanBoogie\ActiveRecord\Table
Methods summary
protected
get_name( void )
protected
get_unprefixed_name( void )
protected
get_primary( void )
protected
get_alias( void )
protected
get_schema( void )
protected
get_parent( void )
public
__construct( array $attributes
)
public
is_installed( void )
: boolean
Checks whether the table is installed.
Checks whether the table is installed.
Returns
boolean
true
if the table exists, false
otherwise.
protected
lazy_get_extended_schema( void )
: array
Returns the extended schema.
Returns the extended schema.
Returns
array
public
resolve_statement( string $statement
)
: string
Resolve statement placeholders.
Resolve statement placeholders.
The following placeholder are replaced:
{alias}
: The alias of the table.
{prefix}
: The prefix used for the tables of the connection.
{primary}
: The primary key of the table.
{self}
: The name of the table.
{self_and_related}
: The escaped name of the table and the possible JOIN clauses.
Note: If the table has a multi-column primary keys {primary}
is replaced by
__multicolumn_primary__<concatened_columns>
where <concatened_columns>
is a the columns
concatenated with an underscore ("_") as separator. For instance, if a table primary key is
made of columns "p1" and "p2", {primary}
is replaced by __multicolumn_primary__p1_p2
.
It's not very helpful, but we still have to decide what to do with this.
Parameters
$statement
- The statement to resolve.
Returns
string
public
quote( $string
, $parameter_type
= \PDO::PARAM_STR )
public
execute( $query
, array $args
= [], array $options
= [] )
: mixed
public
query( string $query
, array $args
= [], array $options
= [] )
: ICanBoogie\ActiveRecord\Statement
Interface to the connection's query() method.
Interface to the connection's query() method.
The statement is resolved using the resolve_statement() method and prepared.
Parameters
Returns
protected
filter_values( array $values
, $extended
= false )
public
save( array $values
, $id
= null, array $options
= [] )
protected
save_callback( array $values
, $id
= null, array $options
= [] )
public
insert( array $values
, array $options
= [] )
: mixed
Inserts values into the table.
Inserts values into the table.
Parameters
$values
- The values to insert.
$options
The following options can be used:
- ignore
: Ignore duplicate errors.
- on duplicate
: specifies the column to update on duplicate, and the values to update
them. If true
the $values
array is used, after the primary keys has been removed.
Returns
mixed
public
update( array $values
, mixed $key
)
: boolean
Update the values of an entry.
Update the values of an entry.
Even if the entry is spread over multiple tables, all the tables are updated in a single
step.
Parameters
Returns
boolean
public
delete( mixed $key
)
: boolean
Deletes a record.
Parameters
$key
- Identifier of the record.
Returns
boolean
public
drop( array $options
= [] )
Constants summary
CONNECTION
: string
'connection'
EXTENDING
: string
'extends'
IMPLEMENTING
: string
'implements'
NAME
: string
Unprefixed Name of the table.
Unprefixed Name of the table.
'name'
Properties summary
protected
$name
: string
Name of the table, including the prefix defined by the model's connection.
Name of the table, including the prefix defined by the model's connection.
protected
$unprefixed_name
The unprefixed name of the table.
The unprefixed name of the table.
Return
string
protected
$primary
: mixed
protected
$alias
: string
Alias for the table's name, which can be defined using the ICanBoogie\ActiveRecord\Table::ALIAS
attribute
or automatically created.
The "{primary}" placeholder used in queries is replaced by the properties value.
protected
$schema
: array
Schema for the table.
The "{alias}" placeholder used in queries is replaced by the properties value.
protected
$parent
: ICanBoogie\ActiveRecord\Table
The parent is used when the table is in a hierarchy, which is the case if the table
extends another table.
The parent is used when the table is in a hierarchy, which is the case if the table
extends another table.
protected
$implements
: array
[]
protected
$update_join
: string
SQL fragment for the FROM clause of the query, made of the table's name and alias and those
of the hierarchy.
SQL fragment for the FROM clause of the query, made of the table's name and alias and those
of the hierarchy.
protected
$select_join
: string
SQL fragment for the FROM clause of the query, made of the table's name and alias and those
of the related tables, inherited and implemented.
SQL fragment for the FROM clause of the query, made of the table's name and alias and those
of the related tables, inherited and implemented.
The "{self_and_related}" placeholder used in queries is replaced by the properties value.
Magic properties
public read-only
$schema
: array
public read-only
$extended_schema
: array
The extended schema of the table.
public read-only
$name
: string
Name of the table, which might include a prefix.
public read-only
$unprefixed_name
: string
Unprefixed name of the table.
public read-only
$primary
: string|array|null
Primary key of the table, or null
if there is none.
public read-only
$alias
: string
The alias name of the table.