From 73b82462fcc757a9ab011a6a86c26c7c29963bd4 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Tue, 1 Jun 2021 09:41:05 -0400 Subject: [PATCH] Add PR #190 - FieldtypeMulti: orderby sort only if schema supports it Co-authored-by: pine3ree --- wire/core/FieldtypeMulti.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wire/core/FieldtypeMulti.php b/wire/core/FieldtypeMulti.php index fcf172ee..108fabc3 100644 --- a/wire/core/FieldtypeMulti.php +++ b/wire/core/FieldtypeMulti.php @@ -454,7 +454,8 @@ abstract class FieldtypeMulti extends Fieldtype { $database = $this->wire('database'); $table = $database->escapeTable($field->table); - $schema = $this->trimDatabaseSchema($this->getDatabaseSchema($field)); + $schemaAll = $this->getDatabaseSchema($field); + $schema = $this->trimDatabaseSchema($schemaAll); $fieldName = $database->escapeCol($field->name); $sanitizer = $this->wire('sanitizer'); $orderByCols = array(); @@ -521,7 +522,7 @@ abstract class FieldtypeMulti extends Fieldtype { if(empty($orderByCols)) { // if there are no orderByCols defined, pagination & sorting not supported // default sort for FieldtypeMulti fields is by column 'sort' - $query->orderby("$table.sort"); + if(isset($schemaAll['sort'])) $query->orderby("$table.sort"); } else { // one or more orderByCols is defined, enabling sorting and potential pagination