1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 00:06:55 +02:00
This commit is contained in:
Ryan Cramer
2024-04-05 13:00:26 -04:00
parent 6aa698343b
commit 7438ae90ca
3 changed files with 23 additions and 9 deletions

View File

@@ -866,18 +866,24 @@ abstract class FieldtypeMulti extends Fieldtype {
*
*/
public function getLoadQueryAutojoin(Field $field, DatabaseQuerySelect $query) {
$database = $this->wire()->database;
if($this->get('useOrderByCols')) {
// autojoin is not used if sorting or pagination is active
$orderByCols = $field->get('orderByCols');
if(count($orderByCols) > 0) return null;
}
$table = $this->database->escapeTable($field->table);
$schema = $this->trimDatabaseSchema($this->getDatabaseSchema($field));
$fieldName = $this->database->escapeCol($field->name);
$table = $database->escapeTable($field->table);
$schemaAll = $this->getDatabaseSchema($field);
$schema = $this->trimDatabaseSchema($schemaAll);
$fieldName = $database->escapeCol($field->name);
$separator = self::multiValueSeparator;
if($field->distinctAutojoin) $table = "DISTINCT $table";
$orderBy = '';
if($field->distinctAutojoin) {
if(isset($schemaAll['sort'])) $orderBy = "ORDER BY $table.sort";
$table = "DISTINCT $table";
}
foreach($schema as $key => $unused) {
$query->select("GROUP_CONCAT($table.$key SEPARATOR '$separator') AS `{$fieldName}__$key`"); // QA
$query->select("GROUP_CONCAT($table.$key $orderBy SEPARATOR '$separator') AS `{$fieldName}__$key`"); // QA
}
return $query;
}
@@ -1039,5 +1045,3 @@ abstract class FieldtypeMulti extends Fieldtype {
}
}