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

index 210df98ac2301ad85021738a58a013f03e9f6226..2fbba50059743a2d62c4d4ce1a5cd4c5f0b3a453 100644 (file)
@@ -23,4 +23,12 @@ trait CubistMagicAttribute
     {
         $this->_attributes[$key] = $value;
     }
+
+    public function setAttributeIfNotSet($key, $value)
+    {
+        if ($this->hasAttribute($key)) {
+            return;
+        }
+        $this->setAttribute($key, $value);
+    }
 }
index c92ae482f4bd73440744d410f4f8365b3a950ef0..08c6d48fe1cf2144a433444a16fb66c0cdc677e1 100644 (file)
@@ -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');
+        }
     }
 }
index 715d4efd23ede73e799399c2097bd0f989afa752..ed8d54fc59effee559d7ec9f57f9b29c9db7ea31 100644 (file)
@@ -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;
                 }
             }