mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Combine extrafield information into one query
Replaces the SQL query per-extrafield to one where all the data is requested.
This commit is contained in:
parent
6c069ce7d5
commit
485f4c3b18
@ -362,17 +362,21 @@ class ManyManyList extends RelationList {
|
||||
user_error('ComponentSet::getExtraData() passed a non-numeric child ID', E_USER_ERROR);
|
||||
}
|
||||
|
||||
// @todo Optimize into a single query instead of one per extra field
|
||||
if($this->extraFields) {
|
||||
foreach($this->extraFields as $fieldName => $dbFieldSpec) {
|
||||
$query = new SQLQuery("\"{$fieldName}\"", "\"{$this->joinTable}\"");
|
||||
if($filter = $this->foreignIDWriteFilter($this->getForeignID())) {
|
||||
$query->setWhere($filter);
|
||||
} else {
|
||||
user_error("Can't call ManyManyList::getExtraData() until a foreign ID is set", E_USER_WARNING);
|
||||
}
|
||||
$query->addWhere("\"{$this->localKey}\" = {$itemID}");
|
||||
$result[$fieldName] = $query->execute()->value();
|
||||
$cleanExtraFields = array();
|
||||
foreach ($this->extraFields as $fieldName => $dbFieldSpec) {
|
||||
$cleanExtraFields[] = "\"{$fieldName}\"";
|
||||
}
|
||||
$query = new SQLQuery($cleanExtraFields, "\"{$this->joinTable}\"");
|
||||
if($filter = $this->foreignIDWriteFilter($this->getForeignID())) {
|
||||
$query->setWhere($filter);
|
||||
} else {
|
||||
user_error("Can't call ManyManyList::getExtraData() until a foreign ID is set", E_USER_WARNING);
|
||||
}
|
||||
$query->addWhere("\"{$this->localKey}\" = {$itemID}");
|
||||
$queryResult = $query->execute()->current();
|
||||
foreach ($queryResult as $fieldName => $value) {
|
||||
$result[$fieldName] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user