fixed the duplicate column for the foriegn key bug

This commit is contained in:
Amine Ben hammou 2017-01-20 18:56:57 +00:00
parent 27dc508bca
commit 057199cb8b
4 changed files with 45 additions and 43 deletions

View File

@ -8,3 +8,4 @@ class Controller extends BaseController
{ {
// //
} }

43
lumen-test/clean.sh Executable file
View File

@ -0,0 +1,43 @@
# models
rm app/*.php 2> /dev/null
# migrations
rm database/migrations/*.php 2> /dev/null
# routes
echo "<?php
\$app->get(\"/\", function () use (\$app) {
return \$app->welcome();
});" > app/Http/routes.php
# Controllers
rm app/Http/Controllers/*.php 2> /dev/null
echo "<?php
namespace App\Http\Controllers;
use Laravel\Lumen\Routing\Controller as BaseController;
class Controller extends BaseController
{
//
}
" > app/Http/Controllers/Controller.php
# factories
echo "<?php
\$factory->define(App\User::class, function (\$faker) {
return [
'name' => \$faker->name,
'email' => \$faker->email,
'password' => str_random(10),
'remember_token' => str_random(10),
];
});
" > database/factories/ModelFactory.php
# database
rm database/database.sqlite 2> /dev/null
touch database/database.sqlite

View File

@ -1,23 +0,0 @@
---
Post:
belongsToMany: tags
add: timestamps softDeletes
fields:
title:
schema: string
rules: required
tags: fillable
content:
schema: text nullable
tags: fillable
published_at:
schema: date
rules: date
tags: date fillable
Tag:
belongsToMany: posts
fields:
name:
schema: string unique
rules: required
tags: fillable

View File

@ -36,7 +36,7 @@ class ResourcesCommand extends BaseCommand {
]); ]);
} }
$this->call('migrate'); // $this->call('migrate'); // actually needed for pivot seeders !
$this->pivotTables = array_map( $this->pivotTables = array_map(
'unserialize', 'unserialize',
@ -72,25 +72,6 @@ class ResourcesCommand extends BaseCommand {
} }
} }
if($i['belongsTo']){
$relations = $this->getArgumentParser('relations')->parse($i['belongsTo']);
foreach ($relations as $relation){
$foreignName = '';
if(! $relation['model']){
$foreignName = snake_case($relation['name']) . '_id';
} else {
$names = array_reverse(explode("\\", $relation['model']));
$foreignName = snake_case($names[0]) . '_id';
}
$i['fields'][$foreignName] = [
'schema' => 'integer',
'tags' => 'key'
];
}
}
if($i['belongsToMany']){ if($i['belongsToMany']){
$relations = $this->getArgumentParser('relations')->parse($i['belongsToMany']); $relations = $this->getArgumentParser('relations')->parse($i['belongsToMany']);
foreach ($relations as $relation){ foreach ($relations as $relation){