protected
array
|
|
protected
array
|
#
get_conditions_args( )
Return the arguments to the conditions.
Return the arguments to the conditions.
Returns
array
|
protected
array
|
#
get_having_args( )
Return the arguments to the HAVING clause.
Return the arguments to the HAVING clause.
Returns
array
|
protected
|
|
public
|
|
public
|
#
__get( $property )
Adds support for model's scopes.
Adds support for model's scopes.
Inheritdoc
|
public
|
#
__call( $method, $arguments )
Override the method to handle magic 'filter_by_' methods.
Override the method to handle magic 'filter_by_' methods.
Inheritdoc
|
public
string
|
#
__toString( )
Convert the query into a string.
Convert the query into a string.
Returns
string
|
protected
string
|
#
render_select( )
Render the SELECT clause.
Render the SELECT clause.
Returns
string
|
protected
string
|
#
render_from( )
Render the FROM clause.
The rendered FROM clause might include some JOINS too.
Returns
string
|
protected
string
|
#
render_main( )
Render the main body of the query, without the SELECT and FROM clauses.
Render the main body of the query, without the SELECT and FROM clauses.
Returns
string
|
protected
string
|
#
render_order( mixed $order )
Render the ORDER clause.
Parameters
Returns
string
|
protected
string
|
#
render_offset_and_limit( integer $offset, integer $limit )
Render the LIMIT and OFFSET clauses.
Render the LIMIT and OFFSET clauses.
Parameters
Returns
string
|
protected
string
|
#
resolve_statement( string $statement )
Resolve the placeholders of a statement.
Resolve the placeholders of a statement.
Note: Currently, the method simply forwards the statement to the model's
resolve_statement() method.
Parameters
Returns
string
|
protected
array
|
#
get_model_scope( )
Return the available scopes for a model class.
Return the available scopes for a model class.
The method uses reflexion to find the scopes, the result is cached.
Returns
array
|
public
ICanBoogie\ActiveRecord\Query
|
#
select( string $expression )
Define the SELECT clause.
Define the SELECT clause.
Parameters
- $expression
- The expression of the
SELECT clause. e.g. 'nid, title'.
Returns
|
public
ICanBoogie\ActiveRecord\Query
|
#
join( string|ICanBoogie\ActiveRecord\Query $expression, array $options = [] )
Add a JOIN clause.
Parameters
- $expression
A join can be created from a model reference,
another query, or a custom JOIN clause.
When $expression is a string starting with : it is considered as a model
reference matching the pattern ":" where <model_id> is the identifier of a model
that can be retrieved with the get_model() function e.g. ":nodes".
When $expression is a ICanBoogie\ActiveRecord\Query instance, it is rendered as a string and used as a
subquery of the JOIN clause. The $options parameter can be used to customize the
output.
Otherwise $expression is considered as a raw JOIN clause.
- $options
Only used if $expression is a ICanBoogie\ActiveRecord\Query instance. The following
options are available:
- mode : Join mode. Default: "INNER"
- alias : The alias of the subquery. Default: The query's model alias.
- on : The column on which to joint is created. Default: The query's model primary key.
<?php
$query->join(':nodes');
$subquery = get_model('updates')
->select('updated_at, $subscriber_id, update_hash')
->order('updated_at DESC')
$query->join($subquery, [ 'on' => 'subscriber_id' ]);
$query->join("INNER JOIN `articles` USING(`nid`)");
Returns
|
public
ICanBoogie\ActiveRecord\Query
|
#
where( mixed $conditions, mixed $conditions_args = null )
Add conditions to the SQL statement.
Add conditions to the SQL statement.
Conditions can either be specified as string or array.
- Pure string conditions
If you'de like to add conditions to your statement, you could just specify them in there,
just like $model->where('order_count = 2'); . This will find all the entries, where the
order_count field's value is 2.
- Array conditions
Now what if that number could vary, say as an argument from somewhere, or perhaps from the
user’s level status somewhere? The find then becomes something like:
$model->where('order_count = ?', 2);
or
$model->where([ 'order_count' => 2 ]);
Or if you want to specify two conditions, you can do it like:
$model->where('order_count = ? AND locked = ?', 2, false);
or
$model->where([ 'order_count' => 2, 'locked' => false ]);
Or if you want to specify subset conditions:
$model->where([ 'order_id' => [ 123, 456, 789 ] ]);
This will return the orders with the order_id 123, 456 or 789.
- Modifiers
When using the "identifier" => "value" notation, you can switch the comparison method by
prefixing the identifier with a bang "!"
$model->where([ '!order_id' => [ 123, 456, 789 ]]);
This will return the orders with the order_id different than 123, 456 and 789.
$model->where([ '!order_count' => 2 ];
This will return the orders with the order_count different than 2.
Parameters
- $conditions
- $conditions_args
Returns
|
public
ICanBoogie\ActiveRecord\Query
|
#
order( string $order_or_field_name, array $field_values = null )
Defines the ORDER clause.
Defines the ORDER clause.
Parameters
- $order_or_field_name
The order for the ORDER clause e.g.
'weight, date DESC', or field to order with, in which case $field_values is required.
- $field_values
- Values of the field specified by
$order_or_field_name .
Returns
|
public
ICanBoogie\ActiveRecord\Query
|
#
group( string $group )
Defines the GROUP clause.
Defines the GROUP clause.
Parameters
Returns
|
public
ICanBoogie\ActiveRecord\Query
|
#
having( mixed $conditions, mixed $conditions_args = null )
Defines the HAVING clause.
Defines the HAVING clause.
Parameters
- $conditions
- $conditions_args
Returns
|
public
ICanBoogie\ActiveRecord\Query
|
#
offset( $offset )
Define the offset of the LIMIT clause.
Define the offset of the LIMIT clause.
Parameters
Returns
|
public
ICanBoogie\ActiveRecord\Query
|
#
limit( integer $limit )
Apply the limit and/or offset to the SQL fired.
Apply the limit and/or offset to the SQL fired.
You can use the limit to specify the number of records to be retrieved, ad use the offset to
specify the number of records to skip before starting to return records:
$model->limit(10);
Will return a maximum of 10 clients and because ti specifies no offset it will return the
first 10 in the table:
$model->limit(5, 10);
Will return a maximum of 10 clients beginning with the 5th.
Parameters
Returns
|
public
ICanBoogie\ActiveRecord\Query
|
#
mode( mixed $mode )
Set the fetch mode for the query.
Set the fetch mode for the query.
Parameters
Returns
See
http://www.php.net/manual/en/pdostatement.setfetchmode.php
|
protected
ICanBoogie\ActiveRecord\Statement
|
#
prepare( )
Prepare the query.
We use the connection's prepare() method because the statement has already been resolved
during the __toString() method and we don't want for the statement to be parsed twice.
Returns
|
protected
ICanBoogie\ActiveRecord\Statement
|
|
public
ICanBoogie\ActiveRecord\Statement
|
#
query( )
Prepare and executes the query.
Prepare and executes the query.
Returns
|
public
array
|
#
all( )
Execute the query and returns an array of records.
Execute the query and returns an array of records.
Returns
array
|
protected
array
|
|
public
mixed
|
#
one( )
Return the first result of the query and close the cursor.
Return the first result of the query and close the cursor.
Returns
mixed The return value of this function on success depends on the fetch mode. In
all cases, FALSE is returned on failure.
|
protected
mixed
|
|
protected
array
|
#
get_pairs( )
Execute que query and return an array of key/value pairs, where the key is the value of
the first column and the value of the key the value of the second column.
Execute que query and return an array of key/value pairs, where the key is the value of
the first column and the value of the key the value of the second column.
Returns
array
|
protected
string
|
#
get_rc( )
Return the value of the first column of the first row.
Return the value of the first column of the first row.
Returns
string
|
public
boolean|array
|
#
exists( mixed $key = null )
Check the existence of records in the model.
Check the existence of records in the model.
$model->exists;
$model->where('name = "max"')->exists;
$model->exists(1);
$model->exists(1, 2);
$model->exists([ 1, 2 ]);
Parameters
Returns
boolean|array
|
protected
boolean|array
|
|
public
integer|array
|
#
count( string $column = null )
Implement the 'COUNT' computation.
Implement the 'COUNT' computation.
Parameters
- $column
- The name of the column to count.
Returns
integer|array
|
protected
integer
|
|
public
integer
|
#
average( string $column )
Implement the 'AVG' computation.
Implement the 'AVG' computation.
Parameters
Returns
integer
|
public
integer
|
#
minimum( string $column )
Implement the 'MIN' computation.
Implement the 'MIN' computation.
Parameters
Returns
integer
|
public
integer
|
#
maximum( string $column )
Implement the 'MAX' computation.
Implement the 'MAX' computation.
Parameters
Returns
integer
|
public
integer
|
#
sum( string $column )
Implement the 'SUM' computation.
Implement the 'SUM' computation.
Parameters
Returns
integer
|
public
boolean
|
#
delete( string $tables = null )
Delete the records matching the conditions and limits of the query.
Delete the records matching the conditions and limits of the query.
Parameters
- $tables
When using a JOIN, $tables is used to specify the tables in which
records should be deleted. Default: The alias of queried model, only if at least one join
clause has been defined using the ICanBoogie\ActiveRecord\Query::$join method.
Returns
boolean The result of the operation.
Todo-20140901:
reflect on join to add the required tables by default, discarding tables
joined with the LEFT mode.
|
public
|
#
getIterator( )
Return an iterator for the query.
Return an iterator for the query.
Implementation of
IteratorAggregate::getIterator()
|