Skip to content

Commit

Permalink
Merge pull request #1 from reliese/master
Browse files Browse the repository at this point in the history
Merge upstream into base
  • Loading branch information
jefhar authored May 23, 2018
2 parents aa18182 + 7d037f2 commit 8fad81f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
4 changes: 2 additions & 2 deletions config/models.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
|
*/

'parent' => Reliese\Database\Eloquent\Model::class,
'parent' => Illuminate\Database\Eloquent\Model::class,

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -386,7 +386,7 @@
*/
'override_pluralize_for' => [

]
],
],

/*
Expand Down
4 changes: 2 additions & 2 deletions src/Coders/Model/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Factory
/**
* @var \Reliese\Meta\SchemaManager
*/
protected $schemas;
protected $schemas = [];

/**
* @var \Illuminate\Filesystem\Filesystem
Expand Down Expand Up @@ -539,7 +539,7 @@ private function formatBaseClasses(Model $model)
*/
private function getBaseClassName(Model $model)
{
return 'Base' . $model->getClassName();
return 'Base'.$model->getClassName();
}

/**
Expand Down
17 changes: 13 additions & 4 deletions src/Coders/Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,20 +408,28 @@ public function shouldQualifyTableName()
*/
public function shouldPluralizeTableName()
{
$pluralize = (bool)$this->config('pluralize', true);
$pluralize = (bool) $this->config('pluralize', true);

$overridePluralizeFor = $this->config('override_pluralize_for', []);
if (count($overridePluralizeFor) > 0) {
foreach ($overridePluralizeFor as $except) {
if ($except == $this->getTable()) {
return !$pluralize;
return ! $pluralize;
}
}
}

return $pluralize;
}

/**
* @return bool
*/
public function shouldLowerCaseTableName()
{
return (bool) $this->config('lower_table_name_first', false);
}

/**
* @param \Reliese\Meta\Blueprint[] $references
*/
Expand Down Expand Up @@ -501,7 +509,7 @@ public function getQualifiedUserClassName()
*/
public function getClassName()
{
if ($this->config('lower_table_name_first', false)) {
if ($this->shouldLowerCaseTableName()) {
return Str::studly(Str::lower($this->getRecordName()));
}

Expand All @@ -516,6 +524,7 @@ public function getRecordName()
if ($this->shouldPluralizeTableName()) {
return Str::singular($this->removeTablePrefix($this->blueprint->table()));
}

return $this->removeTablePrefix($this->blueprint->table());
}

Expand Down Expand Up @@ -699,7 +708,7 @@ public function needsTableName()
return false === $this->shouldQualifyTableName() ||
$this->shouldRemoveTablePrefix() ||
$this->blueprint->table() != Str::plural($this->getRecordName()) ||
!$this->shouldPluralizeTableName();
! $this->shouldPluralizeTableName();
}

/**
Expand Down
15 changes: 8 additions & 7 deletions src/Coders/Model/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,19 @@ public function hint()
*/
public function name()
{
if ($this->parent->shouldPluralizeTableName()) {
if ($this->parent->usesSnakeAttributes()) {
return Str::snake(Str::plural(Str::singular($this->reference->getTable(true))));
}
$tableName = $this->reference->getTable(true);

return Str::camel(Str::plural(Str::singular($this->reference->getTable(true))));
if ($this->parent->shouldLowerCaseTableName()) {
$tableName = strtolower($tableName);
}
if ($this->parent->shouldPluralizeTableName()) {
$tableName = Str::plural(Str::singular($tableName));
}
if ($this->parent->usesSnakeAttributes()) {
return Str::snake($this->reference->getTable(true));
return Str::snake($tableName);
}

return Str::camel($this->reference->getTable(true));
return Str::camel($tableName);
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/Coders/Model/Relations/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Reliese\Coders\Model\Relations;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Collection;

class HasMany extends HasOneOrMany
{
Expand All @@ -27,8 +27,13 @@ public function name()
{
if ($this->parent->shouldPluralizeTableName()) {
$relationBaseName = Str::plural(Str::singular($this->related->getTable(true)));
} else {
$relationBaseName = $this->related->getTable(true);
}

if ($this->parent->shouldLowerCaseTableName()) {
$relationBaseName = strtolower($relationBaseName);
}
$relationBaseName = $this->related->getTable(true);

switch ($this->parent->getRelationNameStrategy()) {
case 'foreign_key':
Expand Down
2 changes: 1 addition & 1 deletion src/Meta/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function primaryKey()
return current($this->unique);
}

$nullPrimaryKey = new Fluent();
$nullPrimaryKey = new Fluent(['columns' => []]);

return $nullPrimaryKey;
}
Expand Down

0 comments on commit 8fad81f

Please sign in to comment.