1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-11 09:14:58 +02:00
This commit is contained in:
Ryan Cramer
2022-12-02 10:45:13 -05:00
parent bceb0160b7
commit b85c1c48b0
4 changed files with 33 additions and 7 deletions

View File

@@ -38,6 +38,7 @@
* @property array $allowContexts Names of settings that are custom configured to be allowed for context. #pw-group-properties * @property array $allowContexts Names of settings that are custom configured to be allowed for context. #pw-group-properties
* @property bool|int|null $flagUnique Non-empty value indicates request for, or presence of, Field::flagUnique flag. #pw-internal * @property bool|int|null $flagUnique Non-empty value indicates request for, or presence of, Field::flagUnique flag. #pw-internal
* @property Fieldgroup|null $_contextFieldgroup Fieldgroup field is in context for or null if not in context. #pw-internal * @property Fieldgroup|null $_contextFieldgroup Fieldgroup field is in context for or null if not in context. #pw-internal
* @property true|null $distinctAutojoin When true and flagAutojoin is set, a distinct autojoin will be used. 3.0.208+ #pw-internal
* *
* Common Inputfield properties that Field objects store: * Common Inputfield properties that Field objects store:
* @property int|bool|null $required Whether or not this field is required during input #pw-group-properties * @property int|bool|null $required Whether or not this field is required during input #pw-group-properties
@@ -812,7 +813,7 @@ class Field extends WireData implements Saveable, Exportable {
$ids[] = (int) $role->id; $ids[] = (int) $role->id;
} else if(is_string($role) && strlen($role)) { } else if(is_string($role) && strlen($role)) {
$rolePage = $this->wire()->roles->get($role); $rolePage = $this->wire()->roles->get($role);
if($rolePage && $rolePage->id) { if($rolePage instanceof Role && $rolePage->id) {
$ids[] = $rolePage->id; $ids[] = $rolePage->id;
} else { } else {
$this->error("Unknown role '$role'"); $this->error("Unknown role '$role'");

View File

@@ -875,6 +875,7 @@ abstract class FieldtypeMulti extends Fieldtype {
$schema = $this->trimDatabaseSchema($this->getDatabaseSchema($field)); $schema = $this->trimDatabaseSchema($this->getDatabaseSchema($field));
$fieldName = $this->database->escapeCol($field->name); $fieldName = $this->database->escapeCol($field->name);
$separator = self::multiValueSeparator; $separator = self::multiValueSeparator;
if($field->distinctAutojoin) $table = "DISTINCT $table";
foreach($schema as $key => $unused) { foreach($schema as $key => $unused) {
$query->select("GROUP_CONCAT($table.$key SEPARATOR '$separator') AS `{$fieldName}__$key`"); // QA $query->select("GROUP_CONCAT($table.$key SEPARATOR '$separator') AS `{$fieldName}__$key`"); // QA
} }

View File

@@ -629,6 +629,7 @@ class PagesLoader extends Wire {
$languages = $this->wire()->languages; $languages = $this->wire()->languages;
$languageIds = array(); $languageIds = array();
$templatesById = array(); $templatesById = array();
$tmpAutojoinFields = array(); // fields to autojoin temporarily, just during this method call
if($languages) foreach($languages as $language) $languageIds[$language->id] = $language->id; if($languages) foreach($languages as $language) $languageIds[$language->id] = $language->id;
@@ -706,15 +707,21 @@ class PagesLoader extends Wire {
} }
} }
// set blank values where joinField didn't appear on page row
foreach($joinFields as $joinField) { foreach($joinFields as $joinField) {
if(isset($row["{$joinField}__data"])) continue;
if(empty($joinResults[$joinField])) continue; // field did not support autojoin if(empty($joinResults[$joinField])) continue; // field did not support autojoin
if(!$template->fieldgroup->hasField($joinField)) continue; if(!$template->fieldgroup->hasField($joinField)) continue;
$field = $page->getField($joinField); $field = $page->getField($joinField);
if(!$field || !$field->type) continue; if(!$field || !$field->type) continue;
$blankValue = $field->type->getBlankValue($page, $field); if(isset($row["{$joinField}__data"])) {
$page->setFieldValue($field->name, $blankValue, false); if(!$field->hasFlag(Field::flagAutojoin)) {
$field->addFlag(Field::flagAutojoin);
$tmpAutojoinFields[$field->id] = $field;
}
} else {
// set blank values where joinField didn't appear on page row
$blankValue = $field->type->getBlankValue($page, $field);
$page->setFieldValue($field->name, $blankValue, false);
}
} }
$page->setIsLoaded(true); $page->setIsLoaded(true);
@@ -731,6 +738,10 @@ class PagesLoader extends Wire {
$pageArray->setTotal($paginationTotal); $pageArray->setTotal($paginationTotal);
$pageArray->resetTrackChanges(true); $pageArray->resetTrackChanges(true);
foreach($tmpAutojoinFields as $field) { /** @var Field $field */
$field->removeFlag(Field::flagAutojoin)->untrackChange('flags');
}
if($useCache) { if($useCache) {
$selectorString = $pageArray->getSelectors(true); $selectorString = $pageArray->getSelectors(true);
$this->pages->cacher()->selectorCache($selectorString, $options, $pageArray); $this->pages->cacher()->selectorCache($selectorString, $options, $pageArray);

View File

@@ -914,6 +914,19 @@ class FieldtypePage extends FieldtypeMulti implements Module, ConfigurableModule
return $query; return $query;
} }
/**
* Return the query used for Autojoining this field
*
* @param Field $field
* @param DatabaseQuerySelect $query
* @return DatabaseQuerySelect|null
*
*/
public function getLoadQueryAutojoin(Field $field, DatabaseQuerySelect $query) {
$field->setQuietly('distinctAutojoin', true);
return parent::getLoadQueryAutojoin($field, $query);
}
/** /**
* Update a DatabaseQuerySelect object to match a Page * Update a DatabaseQuerySelect object to match a Page
* *