]> _ Git - cubist_cms-back.git/commitdiff
#2810
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 5 Jun 2019 14:58:28 +0000 (16:58 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 5 Jun 2019 14:58:28 +0000 (16:58 +0200)
src/app/Magic/Fields/Checkbox.php
src/app/Magic/Fields/Field.php
src/app/Magic/Models/CubistMagicAbstractModel.php

index ce26437e19942844c1727326667ef7bfe4cf33e5..763fe4cf13c1590288c81ddb10acce69f8efef10 100644 (file)
@@ -9,4 +9,5 @@ class Checkbox extends Field
     protected $_adminType = 'checkbox';
     protected $_databaseType = 'boolean';
     protected $_columnType = 'check';
+    protected $_cast = 'boolean';
 }
index a67357e9e7b8c42c851b60234b2c85edfdc0ae50..c92ae482f4bd73440744d410f4f8365b3a950ef0 100644 (file)
@@ -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()
     {
 
index dc568defcb5b7ba0bedf6aa2de81428045ef395d..44fe77d6f90f3e3a13c22062b4432e3674060e98 100644 (file)
@@ -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');
+        }
     }
 
     /**