class DataQuery_SubGroup extends DataQuery implements SQLConditionGroup (View source)

Represents a subgroup inside a WHERE clause in a DataQuery

Stores the clauses for the subgroup inside a specific SQLSelect object. All non-where methods call their DataQuery versions, which uses the base query object.

Traits

Allows an object to have extensions applied to it.

Allows an object to declare a set of custom methods

Properties

protected static array $extra_methods

Custom method sources

from  CustomMethods
protected array $extra_method_registers

Name of methods to invoke by defineMethods for this instance

from  CustomMethods
protected static array $built_in_methods

Non-custom public methods.

from  CustomMethods
protected Extension[] $extension_instances from  Extensible
protected callable[][] $beforeExtendCallbacks

List of callbacks to call prior to extensions having extend called on them, each grouped by methodName.

from  Extensible
protected callable[][] $afterExtendCallbacks

List of callbacks to call after extensions having extend called on them, each grouped by methodName.

from  Extensible
protected string $dataClass from  DataQuery
protected SQLSelect $query from  DataQuery
protected array $collidingFields

Map of all field names to an array of conflicting column SQL

from  DataQuery
protected DataQueryManipulator[] $dataQueryManipulators

Allows custom callback to be registered before getFinalisedQuery is called.

from  DataQuery
protected $querySubclasses from  DataQuery
protected $filterByClassName from  DataQuery
protected SQLSelect $whereQuery
protected SQLSelect $havingQuery

Methods

public
mixed
__call(string $method, array $arguments)

Attempts to locate and call a method dynamically added to a class at runtime if a default cannot be located

protected
defineMethods()

Adds any methods from Extension instances attached to this object.

protected
registerExtraMethodCallback(string $name, callable $callback)

Register an callback to invoke that defines extra methods

public
bool
hasMethod(string $method)

Return TRUE if a method exists on this object

protected
bool
hasCustomMethod($method)

Determines if a custom method with this name is defined.

protected
array
getExtraMethodConfig(string $method)

Get meta-data details on a named method

public
array
allMethodNames(bool $custom = false)

Return the names of all the methods available on this object

protected static 
array
findBuiltInMethods(string|object $class = null)

Get all public built in methods for this class

protected
array
findMethodsFrom(object $object)

Find all methods on the given object.

protected
addMethodsFrom(string $property, string|int $index = null)

Add all the methods from an object property.

protected
removeMethodsFrom(string $property, string|int $index = null)

Add all the methods from an object property (which is an Extension) to this object.

protected
addWrapperMethod(string $method, string $wrap)

Add a wrapper method - a method which points to another method with a different name. For example, Thumbnail(x) can be wrapped to generateThumbnail(x)

protected
addCallbackMethod(string $method, callable $callback)

Add callback as a method.

protected
beforeExtending(string $method, callable $callback)

Allows user code to hook into Object::extend prior to control being delegated to extensions. Each callback will be reset once called.

protected
afterExtending(string $method, callable $callback)

Allows user code to hook into Object::extend after control being delegated to extensions. Each callback will be reset once called.

protected
defineExtensionMethods()

Adds any methods from Extension instances attached to this object.

public static 
bool
add_extension(string $classOrExtension, string $extension = null)

Add an extension to a specific class.

public static 
remove_extension(string $extension)

Remove an extension from a class.

public static 
array
get_extensions(string $class = null, bool $includeArgumentString = false)

No description

public static 
array|null
get_extra_config_sources(string $class = null)

Get extra config sources for this class

public static 
bool
has_extension(string $classOrExtension, string $requiredExtension = null, bool $strict = false)

Return TRUE if a class has a specified extension.

public
array
invokeWithExtensions(string $method, mixed ...$arguments)

Calls a method if available on both this object and all applied Extensions, and then attempts to merge all results into an array

public
array
extend(string $method, mixed ...$arguments)

Run the given function on all of this object's extensions. Note that this method originally returned void, so if you wanted to return results, you're hosed

public
Extension|null
getExtensionInstance(string $extension)

Get an extension instance attached to this object by name.

public
bool
hasExtension(string $extension)

Returns TRUE if this object instance has a specific extension applied in $extension_instances. Extension instances are initialized at constructor time, meaning if you use add_extension() afterwards, the added extension will just be added to new instances of the extended class. Use the static method has_extension() to check if a class (not an instance) has a specific extension.

public
getExtensionInstances()

Get all extension instances for this specific object instance.

public
__construct(DataQuery $base, string $connective)

No description

public
__clone()

Clone this object

public
string
dataClass()

Return the DataObject class that is being queried.

public
query()

Return the SQLSelect object that represents the current query; note that it will be a clone of the object.

public
$this
removeFilterOn(string|array $fieldExpression)

Remove a filter from the query

protected
initialiseQuery()

Set up the simplest initial query

public
$this
setQueriedColumns(array $queriedColumns)

No description

public
getFinalisedQuery(array|null $queriedColumns = null)

Ensure that the query is ready to execute.

protected
ensureSelectContainsOrderbyColumns(SQLSelect $query, array $originalSelect = [])

Ensure that if a query has an order by clause, those columns are present in the select.

public
execute()

Execute the query and return the result as SS_Query object.

public
string
sql(array $parameters = [])

Return this query's SQL

public
int
count()

Return the number of records in this query.

public
bool
exists()

Return whether this dataquery will have records. This will use EXISTS statements in SQL which are more performant - especially when used in combination with indexed columns (that you're filtering on)

public
string
max(string $field)

Return the maximum value of the given field in this DataList

public
string
min(string $field)

Return the minimum value of the given field in this DataList

public
string
avg(string $field)

Return the average value of the given field in this DataList

public
string
sum(string $field)

Return the sum of the values of the given field in this DataList

public
string
aggregate(string $expression)

Runs a raw aggregate expression. Please handle escaping yourself

public
firstRow()

Return the first row that would be returned by this full DataQuery Note that this will issue a separate SELECT ... LIMIT 1 query.

public
lastRow()

Return the last row that would be returned by this full DataQuery Note that this will issue a separate SELECT ... LIMIT query.

protected
selectColumnsFromTable(SQLSelect $query, string $tableClass, array $columns = null)

Update the SELECT clause of the query with the columns from the given table

public
$this
groupby(string $groupby)

Append a GROUP BY clause to this query.

public
$this
having($filter)

Append a HAVING clause to this query.

public
union(SQLSelect $query, string|null $type = null)

Add a query to UNION with.

public
disjunctiveGroup()

Create a disjunctive subgroup.

public
conjunctiveGroup()

Create a conjunctive subgroup

public
with(string $name, SQLSelect $query, array $cteFields = [], bool $recursive = false)

Adds a Common Table Expression (CTE), aka WITH clause.

public
$this
where(string|array|SQLConditionGroup $filter)

Adds a WHERE clause.

public
$this
whereAny(string|array|SQLConditionGroup $filter)

Append a WHERE with OR.

public
$this
sort(string $sort = null, string $direction = null, bool $clear = true)

Set the ORDER BY clause of this query

public
$this
reverseSort()

Reverse order by clause

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

Set the limit of this query.

public
$this
distinct(bool $value)

Set whether this query should be distinct or not.

public
$this
innerJoin(string $table, string $onClause, string $alias = null, int $order = 20, array $parameters = [])

Add an INNER JOIN clause to this query.

public
$this
leftJoin(string $table, string $onClause, string $alias = null, int $order = 20, array $parameters = [])

Add a LEFT JOIN clause to this query.

public
$this
rightJoin(string $table, string $onClause, string $alias = null, int $order = 20, array $parameters = [])

Add a RIGHT JOIN clause to this query.

public static 
string
applyRelationPrefix(string|array $relation)

Prefix of all joined table aliases. E.g. ->filter('Banner.Image.Title)' Will join the Banner, and then Image relations $relationPrefx will be banner_image_ Each table in the Image chain will be suffixed to this prefix. E.g.

public
string
applyRelation(string|array $relation, bool $linearOnly = false)

Traverse the relationship fields, and add the table mappings to the query object state. This has to be called in any overloaded SearchFilter->apply() methods manually.

protected
joinHasManyRelation(string $localClass, string $localField, string $foreignClass, string $localPrefix = null, string $foreignPrefix = null, string $type = 'has_many')

Join the given has_many relation to this query.

protected
joinHasOneRelation(string $localClass, string $localField, string $foreignClass, string $localPrefix = null, string $foreignPrefix = null)

Join the given class to this query with the given key

protected
joinManyManyRelationship(string $relationClass, string $parentClass, string $componentClass, string $parentField, string $componentField, string $relationClassOrTable, string $parentPrefix = null, string $componentPrefix = null)

Join table via many_many relationship

public
$this
subtract(DataQuery $subtractQuery, string $field = 'ID')

Removes the result of query from this query.

public
$this
selectFromTable(string $table, array $fields)

Select the only given fields from the given table.

public
$this
addSelectFromTable(string $table, array $fields)

Add the given fields from the given table to the select statement.

public
array
column(string $field = 'ID')

Query the given field column from the database and return as an array.

protected
string
expressionForField(string $field)

No description

public
selectField(string $fieldExpression, string $alias = null)

Select the given field expressions.

public
$this
setQueryParam(string $key, string|array $value)

Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query.

public
string
getQueryParam(string $key)

Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query.

public
array
getQueryParams()

Returns all query parameters

public
getDataQueryManipulators()

Get query manipulators

public
$this
pushQueryManipulator(DataQueryManipulator $manipulator)

Assign callback to be invoked in getFinalisedQuery()

public
bool
getAllowCollidingFieldStatements()

Get whether field statements aliased as columns are allowed when that column is already being selected

public
setAllowCollidingFieldStatements(bool $value)

Set whether field statements aliased as columns are allowed when that column is already being selected

public
string
conditionSQL(array $parameters)

Determines the resulting SQL along with parameters for the group

Details

mixed __call(string $method, array $arguments)

Attempts to locate and call a method dynamically added to a class at runtime if a default cannot be located

You can add extra methods to a class using Extensions}, {@link Object::createMethod() or Object::addWrapperMethod()

Parameters

string $method
array $arguments

Return Value

mixed

Exceptions

BadMethodCallException

protected defineMethods()

Adds any methods from Extension instances attached to this object.

All these methods can then be called directly on the instance (transparently mapped through __call()}), or called explicitly through {@link extend().

protected registerExtraMethodCallback(string $name, callable $callback)

Register an callback to invoke that defines extra methods

Parameters

string $name
callable $callback

bool hasMethod(string $method)

Return TRUE if a method exists on this object

This should be used rather than PHP's inbuild method_exists() as it takes into account methods added via extensions

Parameters

string $method

Return Value

bool

protected bool hasCustomMethod($method)

Determines if a custom method with this name is defined.

Parameters

$method

Return Value

bool

protected array getExtraMethodConfig(string $method)

Get meta-data details on a named method

Parameters

string $method

Return Value

array

List of custom method details, if defined for this method

array allMethodNames(bool $custom = false)

Return the names of all the methods available on this object

Parameters

bool $custom

include methods added dynamically at runtime

Return Value

array

Map of method names with lowercase keys

static protected array findBuiltInMethods(string|object $class = null)

Get all public built in methods for this class

Parameters

string|object $class

Class or instance to query methods from (defaults to static::class)

Return Value

array

Map of methods with lowercase key name

protected array findMethodsFrom(object $object)

Find all methods on the given object.

Parameters

object $object

Return Value

array

protected addMethodsFrom(string $property, string|int $index = null)

Add all the methods from an object property.

Parameters

string $property

the property name

string|int $index

an index to use if the property is an array

Exceptions

InvalidArgumentException

protected removeMethodsFrom(string $property, string|int $index = null)

Add all the methods from an object property (which is an Extension) to this object.

Parameters

string $property

the property name

string|int $index

an index to use if the property is an array

protected addWrapperMethod(string $method, string $wrap)

Add a wrapper method - a method which points to another method with a different name. For example, Thumbnail(x) can be wrapped to generateThumbnail(x)

Parameters

string $method

the method name to wrap

string $wrap

the method name to wrap to

protected addCallbackMethod(string $method, callable $callback)

Add callback as a method.

Parameters

string $method

Name of method

callable $callback

Callback to invoke. Note: $this is passed as first parameter to this callback and then $args as array

protected beforeExtending(string $method, callable $callback)

Allows user code to hook into Object::extend prior to control being delegated to extensions. Each callback will be reset once called.

Parameters

string $method

The name of the method to hook into

callable $callback

The callback to execute

protected afterExtending(string $method, callable $callback)

Allows user code to hook into Object::extend after control being delegated to extensions. Each callback will be reset once called.

Parameters

string $method

The name of the method to hook into

callable $callback

The callback to execute

protected defineExtensionMethods()

Adds any methods from Extension instances attached to this object.

All these methods can then be called directly on the instance (transparently mapped through __call()}), or called explicitly through {@link extend().

static bool add_extension(string $classOrExtension, string $extension = null)

Add an extension to a specific class.

The preferred method for adding extensions is through YAML config, since it avoids autoloading the class, and is easier to override in more specific configurations.

As an alternative, extensions can be added to a specific class directly in the Object::$extensions array. See SiteTree::$extensions for examples. Keep in mind that the extension will only be applied to new instances, not existing ones (including all instances created through singleton()).

Parameters

string $classOrExtension

Class that should be extended - has to be a subclass of Object

string $extension

Subclass of Extension with optional parameters as a string, e.g. "Versioned"

Return Value

bool

Flag if the extension was added

See also

http://doc.silverstripe.org/framework/en/trunk/reference/dataextension

static remove_extension(string $extension)

Remove an extension from a class.

Note: This will not remove extensions from parent classes, and must be called directly on the class assigned the extension.

Keep in mind that this won't revert any datamodel additions of the extension at runtime, unless its used before the schema building kicks in (in your _config.php). Doesn't remove the extension from any Object instances which are already created, but will have an effect on new extensions. Clears any previously created singletons through singleton() to avoid side-effects from stale extension information.

Parameters

string $extension

class name of an Extension subclass, without parameters

static array get_extensions(string $class = null, bool $includeArgumentString = false)

No description

Parameters

string $class

If omitted, will get extensions for the current class

bool $includeArgumentString

Include the argument string in the return array, FALSE would return array("Versioned"), TRUE returns array("Versioned('Stage','Live')").

Return Value

array

Numeric array of either DataExtension class names, or eval'ed class name strings with constructor arguments.

static array|null get_extra_config_sources(string $class = null)

Get extra config sources for this class

Parameters

string $class

Name of class. If left null will return for the current class

Return Value

array|null

static bool has_extension(string $classOrExtension, string $requiredExtension = null, bool $strict = false)

Return TRUE if a class has a specified extension.

This supports backwards-compatible format (static Object::has_extension($requiredExtension)) and new format ($object->has_extension($class, $requiredExtension))

Parameters

string $classOrExtension

Class to check extension for, or the extension name to check if the second argument is null.

string $requiredExtension

If the first argument is the parent class, this is the extension to check. If left null, the first parameter will be treated as the extension.

bool $strict

if the extension has to match the required extension and not be a subclass

Return Value

bool

Flag if the extension exists

array invokeWithExtensions(string $method, mixed ...$arguments)

Calls a method if available on both this object and all applied Extensions, and then attempts to merge all results into an array

Parameters

string $method

the method name to call

mixed ...$arguments

List of arguments

Return Value

array

List of results with nulls filtered out

array extend(string $method, mixed ...$arguments)

Run the given function on all of this object's extensions. Note that this method originally returned void, so if you wanted to return results, you're hosed

Currently returns an array, with an index resulting every time the function is called. Only adds returns if they're not NULL, to avoid bogus results from methods just defined on the parent extension. This is important for permission-checks through extend, as they use min() to determine if any of the returns is FALSE. As min() doesn't do type checking, an included NULL return would fail the permission checks.

The extension methods are defined during __construct()} in {@link defineMethods().

Parameters

string $method

the name of the method to call on each extension

mixed ...$arguments

Return Value

array

Extension|null getExtensionInstance(string $extension)

Get an extension instance attached to this object by name.

Parameters

string $extension

Return Value

Extension|null

bool hasExtension(string $extension)

Returns TRUE if this object instance has a specific extension applied in $extension_instances. Extension instances are initialized at constructor time, meaning if you use add_extension() afterwards, the added extension will just be added to new instances of the extended class. Use the static method has_extension() to check if a class (not an instance) has a specific extension.

Caution: Don't use singleton()->hasExtension() as it will give you inconsistent results based on when the singleton was first accessed.

Parameters

string $extension

Classname of an Extension subclass without parameters

Return Value

bool

Extension[] getExtensionInstances()

Get all extension instances for this specific object instance.

See get_extensions() to get all applied extension classes for this class (not the instance).

This method also provides lazy-population of the extension_instances property.

Return Value

Extension[]

Map of DataExtension instances, keyed by classname.

__construct(DataQuery $base, string $connective)

No description

Parameters

DataQuery $base
string $connective

__clone()

Clone this object

string dataClass()

Return the DataObject class that is being queried.

Return Value

string

SQLSelect query()

Return the SQLSelect object that represents the current query; note that it will be a clone of the object.

Return Value

SQLSelect

$this removeFilterOn(string|array $fieldExpression)

Remove a filter from the query

Parameters

string|array $fieldExpression

The predicate of the condition to remove (ignoring parameters). The expression will be considered a match if it's contained within any other predicate.

Return Value

$this

protected initialiseQuery()

Set up the simplest initial query

$this setQueriedColumns(array $queriedColumns)

No description

Parameters

array $queriedColumns

Return Value

$this

SQLSelect getFinalisedQuery(array|null $queriedColumns = null)

Ensure that the query is ready to execute.

Parameters

array|null $queriedColumns

Any columns to filter the query by

Return Value

SQLSelect

The finalised sql query

protected ensureSelectContainsOrderbyColumns(SQLSelect $query, array $originalSelect = [])

Ensure that if a query has an order by clause, those columns are present in the select.

Parameters

SQLSelect $query
array $originalSelect

Query execute()

Execute the query and return the result as SS_Query object.

Return Value

Query

string sql(array $parameters = [])

Return this query's SQL

Parameters

array $parameters

Out variable for parameters required for this query

Return Value

string

The resulting SQL query (may be paramaterised)

int count()

Return the number of records in this query.

Note that this will issue a separate SELECT COUNT() query.

Return Value

int

bool exists()

Return whether this dataquery will have records. This will use EXISTS statements in SQL which are more performant - especially when used in combination with indexed columns (that you're filtering on)

Return Value

bool

string max(string $field)

Return the maximum value of the given field in this DataList

Parameters

string $field

Unquoted database column name. Will be ANSI quoted automatically so must not contain double quotes.

Return Value

string

string min(string $field)

Return the minimum value of the given field in this DataList

Parameters

string $field

Unquoted database column name. Will be ANSI quoted automatically so must not contain double quotes.

Return Value

string

string avg(string $field)

Return the average value of the given field in this DataList

Parameters

string $field

Unquoted database column name. Will be ANSI quoted automatically so must not contain double quotes.

Return Value

string

string sum(string $field)

Return the sum of the values of the given field in this DataList

Parameters

string $field

Unquoted database column name. Will be ANSI quoted automatically so must not contain double quotes.

Return Value

string

string aggregate(string $expression)

Runs a raw aggregate expression. Please handle escaping yourself

Parameters

string $expression

An aggregate expression, such as 'MAX("Balance")', or a set of them (as an escaped SQL statement)

Return Value

string

SQLSelect firstRow()

Return the first row that would be returned by this full DataQuery Note that this will issue a separate SELECT ... LIMIT 1 query.

Return Value

SQLSelect

SQLSelect lastRow()

Return the last row that would be returned by this full DataQuery Note that this will issue a separate SELECT ... LIMIT query.

Return Value

SQLSelect

protected selectColumnsFromTable(SQLSelect $query, string $tableClass, array $columns = null)

Update the SELECT clause of the query with the columns from the given table

Parameters

SQLSelect $query
string $tableClass

Class to select from

array $columns

$this groupby(string $groupby)

Append a GROUP BY clause to this query.

Parameters

string $groupby

Escaped SQL statement

Return Value

$this

$this having($filter)

Append a HAVING clause to this query.

Parameters

$filter

Return Value

$this

DataQuery union(SQLSelect $query, string|null $type = null)

Add a query to UNION with.

Parameters

SQLSelect $query
string|null $type

One of the SQLSelect::UNION_ALL or SQLSelect::UNION_DISTINCT constants - or null for a default union

Return Value

DataQuery

DataQuery_SubGroup disjunctiveGroup()

Create a disjunctive subgroup.

That is a subgroup joined by OR

Return Value

DataQuery_SubGroup

DataQuery_SubGroup conjunctiveGroup()

Create a conjunctive subgroup

That is a subgroup joined by AND

Return Value

DataQuery_SubGroup

DataQuery with(string $name, SQLSelect $query, array $cteFields = [], bool $recursive = false)

Adds a Common Table Expression (CTE), aka WITH clause.

Use of this method should usually be within a conditional check against DB::get_conn()->supportsCteQueries().

Parameters

string $name

The name of the WITH clause, which can be referenced in any queries UNIONed to the $query and in this query directly, as though it were a table name.

SQLSelect $query
array $cteFields

Aliases for any columns selected in $query which can be referenced in any queries UNIONed to the $query and in this query directly, as though they were columns in a real table. NOTE: If $query is a DataQuery, then cteFields must be the names of real columns on that DataQuery's data class.

bool $recursive

Return Value

DataQuery

$this where(string|array|SQLConditionGroup $filter)

Adds a WHERE clause.

Parameters

string|array|SQLConditionGroup $filter

Predicate(s) to set, as escaped SQL statements or paramaterised queries

Return Value

$this

$this whereAny(string|array|SQLConditionGroup $filter)

Append a WHERE with OR.

Parameters

string|array|SQLConditionGroup $filter

Predicate(s) to set, as escaped SQL statements or paramaterised queries

Return Value

$this

$this sort(string $sort = null, string $direction = null, bool $clear = true)

Set the ORDER BY clause of this query

Note: while the similarly named DataList::sort() does not allow raw SQL, DataQuery::sort() does allow it

Raw SQL can be vulnerable to SQL injection attacks if used incorrectly, so it's preferable not to use it

Parameters

string $sort

Column to sort on (escaped SQL statement)

string $direction

Direction ("ASC" or "DESC", escaped SQL statement)

bool $clear

Clear existing values

Return Value

$this

See also

\SilverStripe\ORM\Queries\SQLSelect::orderby()

$this reverseSort()

Reverse order by clause

Return Value

$this

DataQuery limit(int|null $limit, int $offset = 0)

Set the limit of this query.

Parameters

int|null $limit
int $offset

Return Value

DataQuery

$this distinct(bool $value)

Set whether this query should be distinct or not.

Parameters

bool $value

Return Value

$this

$this innerJoin(string $table, string $onClause, string $alias = null, int $order = 20, array $parameters = [])

Add an INNER JOIN clause to this query.

Parameters

string $table

The unquoted table name to join to.

string $onClause

The filter for the join (escaped SQL statement)

string $alias

An optional alias name (unquoted)

int $order

A numerical index to control the order that joins are added to the query; lower order values will cause the query to appear first. The default is 20, and joins created automatically by the ORM have a value of 10.

array $parameters

Any additional parameters if the join is a parameterised subquery

Return Value

$this

$this leftJoin(string $table, string $onClause, string $alias = null, int $order = 20, array $parameters = [])

Add a LEFT JOIN clause to this query.

Parameters

string $table

The unquoted table to join to.

string $onClause

The filter for the join (escaped SQL statement).

string $alias

An optional alias name (unquoted)

int $order

A numerical index to control the order that joins are added to the query; lower order values will cause the query to appear first. The default is 20, and joins created automatically by the ORM have a value of 10.

array $parameters

Any additional parameters if the join is a parameterised subquery

Return Value

$this

$this rightJoin(string $table, string $onClause, string $alias = null, int $order = 20, array $parameters = [])

Add a RIGHT JOIN clause to this query.

Parameters

string $table

The unquoted table to join to.

string $onClause

The filter for the join (escaped SQL statement).

string $alias

An optional alias name (unquoted)

int $order

A numerical index to control the order that joins are added to the query; lower order values will cause the query to appear first. The default is 20, and joins created automatically by the ORM have a value of 10.

array $parameters

Any additional parameters if the join is a parameterised subquery

Return Value

$this

static string applyRelationPrefix(string|array $relation)

Prefix of all joined table aliases. E.g. ->filter('Banner.Image.Title)' Will join the Banner, and then Image relations $relationPrefx will be banner_image_ Each table in the Image chain will be suffixed to this prefix. E.g.

banner_image_File and banner_image_Image

This will be null if no relation is joined. E.g. ->filter('Title')

Parameters

string|array $relation

Relation in '.' delimited string, or array of parts

Return Value

string

Table prefix

string applyRelation(string|array $relation, bool $linearOnly = false)

Traverse the relationship fields, and add the table mappings to the query object state. This has to be called in any overloaded SearchFilter->apply() methods manually.

Note, that in order to filter against the joined relation user code must use {\SilverStripe\ORM\tablePrefix()} to get the table alias used for this relation.

Parameters

string|array $relation

The array/dot-syntax relation to follow

bool $linearOnly

Set to true to restrict to linear relations only. Set this if this relation will be used for sorting, and should not include duplicate rows.

Return Value

string

The model class of the related item

protected joinHasManyRelation(string $localClass, string $localField, string $foreignClass, string $localPrefix = null, string $foreignPrefix = null, string $type = 'has_many')

Join the given has_many relation to this query.

Also works with belongs_to

Parameters

string $localClass

Name of class that has the has_many to the joined class

string $localField

Name of the has_many relationship to join

string $foreignClass

Class to join

string $localPrefix

Table prefix for parent class

string $foreignPrefix

Table prefix to use

string $type

'has_many' or 'belongs_to'

protected joinHasOneRelation(string $localClass, string $localField, string $foreignClass, string $localPrefix = null, string $foreignPrefix = null)

Join the given class to this query with the given key

Parameters

string $localClass

Name of class that has the has_one to the joined class

string $localField

Name of the has_one relationship to joi

string $foreignClass

Class to join

string $localPrefix

Table prefix to use for local class

string $foreignPrefix

Table prefix to use for joined table

protected joinManyManyRelationship(string $relationClass, string $parentClass, string $componentClass, string $parentField, string $componentField, string $relationClassOrTable, string $parentPrefix = null, string $componentPrefix = null)

Join table via many_many relationship

Parameters

string $relationClass
string $parentClass
string $componentClass
string $parentField
string $componentField
string $relationClassOrTable

Name of relation table

string $parentPrefix

Table prefix for parent class

string $componentPrefix

Table prefix to use for both joined and mapping table

$this subtract(DataQuery $subtractQuery, string $field = 'ID')

Removes the result of query from this query.

Parameters

DataQuery $subtractQuery
string $field

Return Value

$this

$this selectFromTable(string $table, array $fields)

Select the only given fields from the given table.

Parameters

string $table

Unquoted table name (will be escaped automatically)

array $fields

Database column names (will be escaped automatically)

Return Value

$this

$this addSelectFromTable(string $table, array $fields)

Add the given fields from the given table to the select statement.

Parameters

string $table

Unquoted table name (will be escaped automatically)

array $fields

Database column names (will be escaped automatically)

Return Value

$this

array column(string $field = 'ID')

Query the given field column from the database and return as an array.

querying DB columns of related tables is supported but you need to make sure that the related table is already available in join

Parameters

string $field

See expressionForField().

Return Value

array

List of column values for the specified column

Exceptions

InvalidArgumentException

See also

DataList::applyRelation example use: column("MyTable"."Title") or $columnName = null; Category::get() ->applyRelation('Products.Title', $columnName) ->column($columnName);

protected string expressionForField(string $field)

No description

Parameters

string $field

Select statement identifier, either the unquoted column name, the full composite SQL statement, or the alias set through SQLSelect->selectField().

Return Value

string

The expression used to query this field via this DataQuery

selectField(string $fieldExpression, string $alias = null)

Select the given field expressions.

Parameters

string $fieldExpression

String The field to select (escaped SQL statement)

string $alias

String The alias of that field (escaped SQL statement)

$this setQueryParam(string $key, string|array $value)

Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query.

It's expected that the $key will be namespaced, e.g, 'Versioned.stage' instead of just 'stage'.

Parameters

string $key
string|array $value

Return Value

$this

string getQueryParam(string $key)

Set an arbitrary query parameter, that can be used by decorators to add additional meta-data to the query.

Parameters

string $key

Return Value

string

array getQueryParams()

Returns all query parameters

Return Value

array

query parameters array

DataQueryManipulator[] getDataQueryManipulators()

Get query manipulators

Return Value

DataQueryManipulator[]

$this pushQueryManipulator(DataQueryManipulator $manipulator)

Assign callback to be invoked in getFinalisedQuery()

Parameters

DataQueryManipulator $manipulator

Return Value

$this

bool getAllowCollidingFieldStatements()

Get whether field statements aliased as columns are allowed when that column is already being selected

Return Value

bool

DataQuery setAllowCollidingFieldStatements(bool $value)

Set whether field statements aliased as columns are allowed when that column is already being selected

Parameters

bool $value

Return Value

DataQuery

string conditionSQL(array $parameters)

Determines the resulting SQL along with parameters for the group

Parameters

array $parameters

Out list of parameters

Return Value

string

The complete SQL string for this item