From d1afc9b20ad4c3cf8dc5294db553c31ebf9b21fc Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 5 Jun 2019 16:58:28 +0200 Subject: [PATCH] #2810 --- src/app/Magic/Fields/Checkbox.php | 1 + src/app/Magic/Fields/Field.php | 5 ++++- src/app/Magic/Models/CubistMagicAbstractModel.php | 9 ++++++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/Magic/Fields/Checkbox.php b/src/app/Magic/Fields/Checkbox.php index ce26437..763fe4c 100644 --- a/src/app/Magic/Fields/Checkbox.php +++ b/src/app/Magic/Fields/Checkbox.php @@ -9,4 +9,5 @@ class Checkbox extends Field protected $_adminType = 'checkbox'; protected $_databaseType = 'boolean'; protected $_columnType = 'check'; + protected $_cast = 'boolean'; } diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index a67357e..c92ae48 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -16,9 +16,11 @@ class Field protected $_rules = []; protected $_adminType = 'text'; protected $_databaseType = 'text'; + protected $_cast = false; protected $_databaseUnique = false; protected $_databaseIndex = false; protected $_translatable = false; + protected $_databaseAttributes = []; /** @@ -63,7 +65,7 @@ class Field { return ['type' => $this->_adminType, 'column' => false, 'form' => 'both', 'rules' => '', 'fillable' => true, 'guarded' => false, 'hidden' => false, 'translatable' => $this->_translatable, - 'column_type' => 'text', 'default' => '']; + 'column_type' => 'text', 'default' => '', 'cast' => $this->_cast]; } public function __construct($attributes) @@ -135,6 +137,7 @@ class Field return null; } + protected function _postSetAttributes() { diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index dc568de..44fe77d 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -158,7 +158,10 @@ class CubistMagicAbstractModel extends Model /** @var Field $field */ $field = Field::getInstance($attributes); if (null !== $field->getRelationship()) { - $this->_addRelationship($field); + $continue = $this->_addRelationship($field); + if (!$continue) { + return; + } } $name = $field->getAttribute('name'); @@ -175,6 +178,10 @@ class CubistMagicAbstractModel extends Model if ($field->getAttribute('translatable')) { $this->translatable[] = $name; } + + if ($field->getAttribute('cast', false) !== false) { + $this->casts[$field->getAttribute('name')] = $field->getAttribute('name'); + } } /** -- 2.39.5