Class Table
A representation of a database table.
-
ICanBoogie\Prototyped
-
┗
ICanBoogie\ActiveRecord\Table
Methods summary
protected
get_name( void )
: string
protected
get_unprefixed_name( void )
: string
protected
get_primary( void )
: array|null|string
Returns
array|null|string
protected
get_alias( void )
: string
protected
get_schema_options( void )
: array
protected
lazy_get_update_join( void )
: string
protected
lazy_get_select_join( void )
: string
public
__construct( array $attributes
)
protected
map_construct_attributes( array $attributes
)
Maps construct attributes.
Maps construct attributes.
Parameters
protected
assert_has_name( void )
Asserts that the table has a name.
Asserts that the table has a name.
protected
assert_has_schema( void )
Asserts that the table has a schema.
Asserts that the table has a schema.
protected
assert_has_connection( void )
Asserts that the table has a valid connection.
Asserts that the table has a valid connection.
protected
assert_parent_is_valid( void )
Asserts the parent is valid, if one is specified.
Asserts the parent is valid, if one is specified.
protected
assert_implements_is_valid( void )
Asserts the implements definition is valid.
Asserts the implements definition is valid.
protected
ensure_has_alias( void )
Ensures the table has an alias, make one otherwise.
Ensures the table has an alias, make one otherwise.
protected
construct_with_parent( ICanBoogie\ActiveRecord\Table
$parent
)
Construct table with specified parent.
Construct table with specified parent.
From its parent, a table inherits its primary key, schema options, and implements.
Parameters
public
install( void )
Creates table.
Throws
Exception
if install fails.
public
uninstall( void )
Drops table.
Throws
Exception
if uninstall fails.
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.
public
resolve_statement( string $statement
)
: string
Resolves statement placeholders.
Resolves 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 $string
, integer $parameter_type
= \PDO::PARAM_STR )
: string
Parameters
Returns
string
See
Connection::quote()
public
execute( string $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
, boolean|false $extended
= false )
: array
Filters mass assignment values.
Filters mass assignment values.
Parameters
Returns
array
public
save( array $values
, mixed|null $id
= null, array $options
= [] )
: mixed
Saves values.
Parameters
Returns
mixed
Throws
Exception
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
truncate( void )
: mixed
Truncates table.
Returns
mixed
Fixme-20081223:
what about extends ?
public
drop( array $options
= [] )
: mixed
Drops table.
Parameters
Returns
mixed
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
: array|null|string
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_options
: array
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_options
: array
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.