diff --git a/src/Model.php b/src/Model.php index 2aa8108e2b..2ed67ecad0 100644 --- a/src/Model.php +++ b/src/Model.php @@ -577,19 +577,22 @@ public function allFields() return $this; } - private function checkOnlyFieldsField(string $field) + private function checkOnlyFieldsField(string $fieldName) { - $this->getField($field); // test if field exists + $field = $this->getField($fieldName); // test if field exists - if ($this->only_fields) { - if (!in_array($field, $this->only_fields, true) && !$this->getField($field)->system) { - throw (new Exception('Attempt to use field outside of those set by onlyFields')) - ->addMoreInfo('field', $field) - ->addMoreInfo('only_fields', $this->only_fields); - } + if (!$this->isOnlyField($fieldName) && !$field->system) { + throw (new Exception('Attempt to use field outside of those set by onlyFields')) + ->addMoreInfo('field', $fieldName) + ->addMoreInfo('only_fields', $this->only_fields); } } + public function isOnlyField(string $fieldName) + { + return !$this->only_fields || in_array($fieldName, $this->only_fields, true); + } + /** * Will return true if specified field is dirty. */ @@ -663,11 +666,6 @@ public function getFields($filter = null): array }, ARRAY_FILTER_USE_BOTH); } - public function isOnlyField($fieldName) - { - return !$this->only_fields || in_array($fieldName, $this->only_fields, true); - } - /** * Set field value. *