From: Vincent Vanwaelscappel Date: Wed, 5 Jun 2019 17:15:29 +0000 (+0200) Subject: #2810 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=62065891115c8ad7776a9490f1251ee9fcb3712e;p=cubist_cms-back.git #2810 --- diff --git a/src/app/Magic/CubistMagicAttribute.php b/src/app/Magic/CubistMagicAttribute.php index 210df98..2fbba50 100644 --- a/src/app/Magic/CubistMagicAttribute.php +++ b/src/app/Magic/CubistMagicAttribute.php @@ -23,4 +23,12 @@ trait CubistMagicAttribute { $this->_attributes[$key] = $value; } + + public function setAttributeIfNotSet($key, $value) + { + if ($this->hasAttribute($key)) { + return; + } + $this->setAttribute($key, $value); + } } diff --git a/src/app/Magic/Fields/Field.php b/src/app/Magic/Fields/Field.php index c92ae48..08c6d48 100644 --- a/src/app/Magic/Fields/Field.php +++ b/src/app/Magic/Fields/Field.php @@ -65,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' => '', 'cast' => $this->_cast]; + 'column_type' => 'text', 'default' => '', 'cast' => $this->_cast, 'fake' => false, 'store_in' => false]; } public function __construct($attributes) @@ -140,6 +140,8 @@ class Field protected function _postSetAttributes() { - + if ($this->getAttribute('fake', false) === true) { + $this->setAttributeIfNotSet('store_in', 'extras'); + } } } diff --git a/src/app/Magic/Models/CubistMagicAbstractModel.php b/src/app/Magic/Models/CubistMagicAbstractModel.php index 715d4ef..ed8d54f 100644 --- a/src/app/Magic/Models/CubistMagicAbstractModel.php +++ b/src/app/Magic/Models/CubistMagicAbstractModel.php @@ -175,10 +175,11 @@ 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'); } + + } /** @@ -271,10 +272,22 @@ class CubistMagicAbstractModel extends Model } } + $fakeColumns = []; + foreach ($this->_fields as $field) { - if ($field->getRelationship() != 'belongsToMany') { - $field->defineDbColumn($table); + if ($field->getRelationship() == 'belongsToMany') { + continue; } + if ($field->getAttribute('store_in', false) !== false) { + $fakeColumns[] = $field->getAttribute('store_in'); + continue; + } + $field->defineDbColumn($table); + } + + $fakeColumns = array_unique($fakeColumns); + foreach ($fakeColumns as $fakeColumn) { + $table->addColumn($fakeColumn, 'text'); } if ($this->timestamps) { @@ -321,8 +334,8 @@ class CubistMagicAbstractModel extends Model { if (is_string($field)) { foreach ($this->_fields as $f) { - if($f->getAttribute('entity')==$field){ - $field=$f; + if ($f->getAttribute('entity') == $field) { + $field = $f; break; } }