]> _ Git - cubist_cms-back.git/commitdiff
#2810
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 3 Jun 2019 14:20:39 +0000 (16:20 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 3 Jun 2019 14:20:39 +0000 (16:20 +0200)
src/app/Console/Commands/GenerateCommand.php
src/app/Magic/Fields/SelectFromModel.php
src/app/Magic/Models/CubistMagicAbstractModel.php

index fbdde8298e65261574bfc66f9d051c6c07409e6f..d40aa23242366bfd1b132bec6bdfe03dd210a5d8 100644 (file)
@@ -45,7 +45,7 @@ class GenerateCommand extends CubistCommand
             mkdir($routesDir, 0777, true);
         }
         $stub = file_get_contents(Util::getStubPath() . '/routes.stub');
-        $stub = str_replace('_CUSTOM_', implode("\n", $this->_routes), $stub);
+        $stub = str_replace('_CUSTOM_', implode("\n    ", $this->_routes), $stub);
 
         file_put_contents($routesDir . '/custom.php', $stub);
     }
index 0040e581fe3df4e3a74628df977fc334bfc1763b..e2db27f00377aa0e2a3a5858e5bd0f0b1650e709 100644 (file)
@@ -7,7 +7,7 @@ namespace Cubist\Backpack\app\Magic\Fields;
 class SelectFromModel extends Model
 {
     protected $_adminType = 'select2';
-    protected $_databaseType = 'string';
+    protected $_databaseType = 'text';
     protected $_multiple = false;
 
 
index 017395ce7a01284c7bc33c8b7fbc9684e12d85b6..57a0c47c38e08a17b96a46ba7d76bcd26a451ac6 100644 (file)
@@ -224,13 +224,6 @@ class CubistMagicAbstractModel extends Model
 
         $table->setPrimaryKey([$this->primaryKey], 'pk_' . $this->table);
 
-        foreach ($this->_fields as $field) {
-            $field->defineDbColumn($table);
-        }
-
-        if ($this->timestamps) {
-            $this->_addTimestampsDatabaseColumns($table);
-        }
 
         foreach ($this->_relationships as $relationship) {
             if ($relationship->getRelationship() === 'belongsToMany') {
@@ -246,6 +239,17 @@ class CubistMagicAbstractModel extends Model
             }
         }
 
+        foreach ($this->_fields as $field) {
+            if ($field->getRelationship() == 'belongsToMany') {
+                $field->defineDbColumn($table);
+            }
+        }
+
+        if ($this->timestamps) {
+            $this->_addTimestampsDatabaseColumns($table);
+        }
+
+
         return $table;
     }
 
@@ -269,8 +273,8 @@ class CubistMagicAbstractModel extends Model
     public function __call($method, $parameters)
     {
         foreach ($this->_relationships as $relationship) {
-            /** @var $relationship ['field'] Field */
-            if ($method == $relationship['field']->getAttrbute('name')) {
+            /** @var $relationship Field */
+            if ($method == $relationship->getAttrbute('name')) {
                 return $this->relationship($relationship);
             }
         }