From a4caba45c830293b5f5a1fc8cfedff282993cdac Mon Sep 17 00:00:00 2001 From: Elias Luhr Date: Mon, 11 Oct 2021 13:50:07 +0200 Subject: [PATCH] updated model and crud generation --- src/generators/crud/ModelTrait.php | 1 + src/generators/crud/default/views/view.php | 10 ++++++---- .../crud/providers/core/RelationProvider.php | 10 ++++++---- src/generators/model/Generator.php | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/generators/crud/ModelTrait.php b/src/generators/crud/ModelTrait.php index 0d1732b..4fb3c5a 100644 --- a/src/generators/crud/ModelTrait.php +++ b/src/generators/crud/ModelTrait.php @@ -152,6 +152,7 @@ public function getColumnByAttribute($attribute, $model = null) $model = $this; } + // omit schema for NOSQL models if (method_exists($model,'getTableSchema') && $model->getTableSchema()) { return $model->getTableSchema()->getColumn($attribute); diff --git a/src/generators/crud/default/views/view.php b/src/generators/crud/default/views/view.php index 9f0f7bf..b43fd38 100644 --- a/src/generators/crud/default/views/view.php +++ b/src/generators/crud/default/views/view.php @@ -159,10 +159,11 @@ $showAllRecords = false; if ($relation->via !== null) { + $modelNameByTable = $generator->getModelByTableName($relation->via->from[0]); if ($generator->disablePluralization) { - $pivotName = $name; + $pivotName = $modelNameByTable; } else { - $pivotName = Inflector::pluralize($generator->getModelByTableName($relation->via->from[0])); + $pivotName = Inflector::pluralize($modelNameByTable); } $pivotRelation = $model->{'get'.$pivotName}(); $pivotPk = key($pivotRelation->link); @@ -181,7 +182,8 @@ } // relation list, add, create buttons - echo "
\n
\n"; +// echo "
\n
\n"; + echo "
\n"; echo " \n
\n"; #
\n"; + echo "
\n
"; #
\n"; // render pivot grid if ($relation->via !== null) { $pjaxId = "pjax-{$pivotName}"; diff --git a/src/generators/crud/providers/core/RelationProvider.php b/src/generators/crud/providers/core/RelationProvider.php index 68272c1..8f2cba6 100644 --- a/src/generators/crud/providers/core/RelationProvider.php +++ b/src/generators/crud/providers/core/RelationProvider.php @@ -141,7 +141,9 @@ public function attributeFormat($attribute) $routeIndex = $this->generator->createRelationRoute($relation, 'index'); $modelClass = $this->generator->modelClass; - $relationProperty = lcfirst((new ModelGenerator())->generateRelationName( + $relationProperty = lcfirst((new ModelGenerator([ + 'disablePluralization' => $this->generator->disablePluralization + ]))->generateRelationName( [$relation], $modelClass::getTableSchema(), $column->name, @@ -315,7 +317,7 @@ public function relationGrid($name, $relation, $showAllRecords = false) 'class' => '{$this->generator->actionButtonClass}', 'template' => '$template', 'contentOptions' => ['nowrap'=>'nowrap'], - 'urlCreator' => function (\$action, \$model, \$key, \$index) { + 'urlCreator' => function (\$action, \$model, \$key) { // using the column name as key, not mapping to 'id' like the standard generator \$params = is_array(\$key) ? \$key : [\$model->primaryKey()[0] => (string) \$key]; \$params[0] = '$controller' . '/' . \$action; @@ -330,7 +332,7 @@ public function relationGrid($name, $relation, $showAllRecords = false) EOS; // add action column - if ($this->generator->actionButtonColumnPosition != 'right') { + if ($this->generator->actionButtonColumnPosition !== 'right') { $columns .= $actionColumn . ",\n"; } @@ -363,7 +365,7 @@ public function relationGrid($name, $relation, $showAllRecords = false) ++$counter; } - if ($this->generator->actionButtonColumnPosition == 'right') { + if ($this->generator->actionButtonColumnPosition === 'right') { $columns .= $actionColumn . ",\n"; } diff --git a/src/generators/model/Generator.php b/src/generators/model/Generator.php index ac6a51f..e493a63 100644 --- a/src/generators/model/Generator.php +++ b/src/generators/model/Generator.php @@ -463,7 +463,7 @@ public function generateRelationName($relations, $table, $key, $multiple) $suffix = ''; if ($this->disablePluralization) { if ($multiple) { - $suffix = 'N'; +// $suffix = 'N'; } $multiple = false; }