mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-01 21:58:51 +02:00
Deprecate Aggregate and DataObject::getComponentsQuery
This commit is contained in:
parent
10b55170ea
commit
0e443bafa0
@ -29,6 +29,8 @@
|
|||||||
* NOTE: The cache logic uses tags, and so a backend that supports tags is required. Currently only the File
|
* NOTE: The cache logic uses tags, and so a backend that supports tags is required. Currently only the File
|
||||||
* backend (and the two-level backend with the File backend as the slow store) meets this requirement
|
* backend (and the two-level backend with the File backend as the slow store) meets this requirement
|
||||||
*
|
*
|
||||||
|
* @deprecated 3.1 Use DataList to aggregate data
|
||||||
|
*
|
||||||
* @author hfried
|
* @author hfried
|
||||||
* @package framework
|
* @package framework
|
||||||
* @subpackage core
|
* @subpackage core
|
||||||
@ -60,10 +62,15 @@ class Aggregate extends ViewableData {
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
* @deprecated 3.1 Use DataList to aggregate data
|
||||||
|
*
|
||||||
* @param string $type The DataObject type we are building an aggregate for
|
* @param string $type The DataObject type we are building an aggregate for
|
||||||
* @param string $filter (optional) An SQL filter to apply to the selected rows before calculating the aggregate
|
* @param string $filter (optional) An SQL filter to apply to the selected rows before calculating the aggregate
|
||||||
*/
|
*/
|
||||||
public function __construct($type, $filter = '') {
|
public function __construct($type, $filter = '') {
|
||||||
|
Deprecation::notice('3.1', 'Call aggregate methods on a DataList directly instead. In templates'
|
||||||
|
. ' an example of the new syntax is <% cached List(Member).max(LastEdited) %> instead'
|
||||||
|
. ' (check partial-caching.md documentation for more details.)');
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
$this->filter = $filter;
|
$this->filter = $filter;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
@ -1468,39 +1468,11 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the query object for a $has_many Component.
|
* @deprecated 3.1 Use getComponents to get a filtered DataList for an object's relation
|
||||||
*
|
|
||||||
* @param string $componentName
|
|
||||||
* @param string $filter
|
|
||||||
* @param string|array $sort
|
|
||||||
* @param string $join Deprecated, use leftJoin($table, $joinClause) instead
|
|
||||||
* @param string|array $limit
|
|
||||||
* @return SQLQuery
|
|
||||||
*/
|
*/
|
||||||
public function getComponentsQuery($componentName, $filter = "", $sort = "", $join = "", $limit = "") {
|
public function getComponentsQuery($componentName, $filter = "", $sort = "", $join = "", $limit = "") {
|
||||||
if(!$componentClass = $this->has_many($componentName)) {
|
Deprecation::notice('3.1', "Use getComponents to get a filtered DataList for an object's relation");
|
||||||
user_error("DataObject::getComponentsQuery(): Unknown 1-to-many component '$componentName'"
|
return $this->getComponents($componentName, $filter, $sort, $join, $limit);
|
||||||
. " on class '$this->class'", E_USER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($join) {
|
|
||||||
throw new \InvalidArgumentException(
|
|
||||||
'The $join argument has been removed. Use leftJoin($table, $joinClause) instead.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$joinField = $this->getRemoteJoinField($componentName, 'has_many');
|
|
||||||
|
|
||||||
$id = $this->getField("ID");
|
|
||||||
|
|
||||||
// get filter
|
|
||||||
$combinedFilter = "\"$joinField\" = '$id'";
|
|
||||||
if(!empty($filter)) $combinedFilter .= " AND ({$filter})";
|
|
||||||
|
|
||||||
return DataList::create($componentClass)
|
|
||||||
->where($combinedFilter)
|
|
||||||
->canSortBy($sort)
|
|
||||||
->limit($limit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user