From: Vincent Vanwaelscappel Date: Thu, 20 Jun 2019 14:26:18 +0000 (+0200) Subject: #2843 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=a382663f094ed013cc5c0039ced51c48bc6dd347;p=cubist_cms-back.git #2843 --- diff --git a/src/app/Magic/BunchOfFields.php b/src/app/Magic/BunchOfFields.php index e042208..51afa4f 100644 --- a/src/app/Magic/BunchOfFields.php +++ b/src/app/Magic/BunchOfFields.php @@ -26,6 +26,11 @@ trait BunchOfFields return $field; } + /** + * @param array $attributes + * @return Field + * @throws \Exception + */ public function addFakeField(array $attributes) { $attributes['fake'] = true; diff --git a/src/app/Magic/CubistMagicAttribute.php b/src/app/Magic/CubistMagicAttribute.php index 70c70cd..0447ff1 100644 --- a/src/app/Magic/CubistMagicAttribute.php +++ b/src/app/Magic/CubistMagicAttribute.php @@ -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); diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index c6cfc7f..528db59 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -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')) { diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index f8bc34a..4f6ca8b 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -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'); }