mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge pull request #2202 from tractorcow/3.1-aggregate-deprecation
API Deprecate Aggregate and DataObject::getComponentsQuery
This commit is contained in:
commit
84bc3ed024
@ -29,6 +29,8 @@
|
||||
* 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
|
||||
*
|
||||
* @deprecated 3.1 Use DataList to aggregate data
|
||||
*
|
||||
* @author hfried
|
||||
* @package framework
|
||||
* @subpackage core
|
||||
@ -60,10 +62,15 @@ class Aggregate extends ViewableData {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @deprecated 3.1 Use DataList to aggregate data
|
||||
*
|
||||
* @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
|
||||
*/
|
||||
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->filter = $filter;
|
||||
parent::__construct();
|
||||
|
@ -1468,39 +1468,11 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the query object for a $has_many Component.
|
||||
*
|
||||
* @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
|
||||
* @deprecated 3.1 Use getComponents to get a filtered DataList for an object's relation
|
||||
*/
|
||||
public function getComponentsQuery($componentName, $filter = "", $sort = "", $join = "", $limit = "") {
|
||||
if(!$componentClass = $this->has_many($componentName)) {
|
||||
user_error("DataObject::getComponentsQuery(): Unknown 1-to-many component '$componentName'"
|
||||
. " 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);
|
||||
Deprecation::notice('3.1', "Use getComponents to get a filtered DataList for an object's relation");
|
||||
return $this->getComponents($componentName, $filter, $sort, $join, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user