]> _ Git - cubist_cms-back.git/commitdiff
#2843
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 20 Jun 2019 14:26:18 +0000 (16:26 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 20 Jun 2019 14:26:18 +0000 (16:26 +0200)
src/app/Magic/BunchOfFields.php
src/app/Magic/CubistMagicAttribute.php
src/app/Magic/Fields/Field.php
src/app/Magic/Models/CubistMagicAbstractModel.php

index e042208f07ca80765d51ddde90c28c525dbfce86..51afa4feb428663baa1bbfcfe6043161a0a0ef8c 100644 (file)
@@ -26,6 +26,11 @@ trait BunchOfFields
         return $field;
     }
 
+    /**
+     * @param array $attributes
+     * @return Field
+     * @throws \Exception
+     */
     public function addFakeField(array $attributes)
     {
         $attributes['fake'] = true;
index 70c70cd2465d31079ea2648ea76311a1c1f0afff..0447ff1ceb850f41b7623e670bc40af05ed072eb 100644 (file)
@@ -34,7 +34,7 @@ trait CubistMagicAttribute
     public function setAttributeIfNotSet($key, $value)
     {
         $k = $this->_attribute($key);
-        if ($this->getAttribute($key, null) !== null) {
+        if ($this->hasAttribute($key)) {
             return;
         }
         $this->setAttribute($k, $value);
index c6cfc7f03c6912e77d6abb3300dada1973b784c3..528db59ccb5c6150e77940b3d9701e01e2dc293d 100644 (file)
@@ -99,7 +99,7 @@ class Field implements \ArrayAccess
             'fillable' => true, 'guarded' => false, 'hidden' => false, 'translatable' => $this->_translatable,
             'column_type' => $this->_columnType, 'default' => '', 'cast' => $this->_cast, 'column_view_namespace' => $this->_columnViewNamespace, 'searchLogic' => $this->_searchLogic,
             'allow_null' => true,
-            'fake' => false, 'store_in' => false, 'attributes' => [],];
+            'fake' => false, 'store_in' => 'extras', 'attributes' => [],];
     }
 
     public function __construct($attributes)
@@ -192,7 +192,7 @@ class Field implements \ArrayAccess
 
     protected function _postSetAttributes()
     {
-        if ($this->getAttribute('fake', false) === true) {
+        if ($this->getAttribute('fake')) {
             $this->setAttributeIfNotSet('store_in', 'extras');
         }
         if ($this->hasAttribute('when')) {
index f8bc34a9840d7e3238e69a8aee327b4189ac617c..4f6ca8bbb2739279255db9d25d33803810011917 100644 (file)
@@ -205,9 +205,8 @@ class CubistMagicAbstractModel extends Model implements HasMedia
             if (!isset($this->casts[$store_in])) {
                 $this->casts[$store_in] = 'array';
             }
-            if (!in_array($store_in, $this->fakeColumns)) {
-                $this->fakeColumns[] = $store_in;
-            }
+
+            $this->fakeColumns[$store_in] = true;
         } else {
             if ($field->getAttribute('fillable')) {
                 $this->fillable[] = $name;
@@ -320,21 +319,17 @@ class CubistMagicAbstractModel extends Model implements HasMedia
             }
         }
 
-        $fakeColumns = [];
-
         foreach ($this->_fields as $field) {
             if ($field->getRelationship() == 'belongsToMany') {
                 continue;
             }
-            if ($field->getAttribute('store_in', false) !== false) {
-                $fakeColumns[] = $field->getAttribute('store_in');
+            if ($field->getAttribute('fake', false) !== false) {
                 continue;
             }
             $field->defineDbColumn($table);
         }
 
-        $fakeColumns = array_unique($fakeColumns);
-        foreach ($fakeColumns as $fakeColumn) {
+        foreach ($this->fakeColumns as $fakeColumn => $true) {
             $table->addColumn($fakeColumn, 'text');
         }