Skip to content

Commit

Permalink
updated model and crud generation
Browse files Browse the repository at this point in the history
  • Loading branch information
eluhr committed Oct 11, 2021
1 parent e98dc79 commit a4caba4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/generators/crud/ModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions src/generators/crud/default/views/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -181,7 +182,8 @@
}

// relation list, add, create buttons
echo "<div style='position: relative'>\n<div style='position:absolute; right: 0px; top: 0px;'>\n";
// echo "<div style='position: relative'>\n<div style='position:absolute; right: 0px; top: 0px;'>\n";
echo "<div style='float:right;'>\n";

echo " <?php
echo Html::a(
Expand Down Expand Up @@ -211,7 +213,7 @@

echo $addButton;

echo "</div>\n</div>\n"; #<div class='clearfix'></div>\n";
echo "</div>\n<div class='clearfix'></div>"; #<div class='clearfix'></div>\n";
// render pivot grid
if ($relation->via !== null) {
$pjaxId = "pjax-{$pivotName}";
Expand Down
10 changes: 6 additions & 4 deletions src/generators/crud/providers/core/RelationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -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";
}

Expand Down Expand Up @@ -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";
}

Expand Down
2 changes: 1 addition & 1 deletion src/generators/model/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public function generateRelationName($relations, $table, $key, $multiple)
$suffix = '';
if ($this->disablePluralization) {
if ($multiple) {
$suffix = 'N';
// $suffix = 'N';
}
$multiple = false;
}
Expand Down

0 comments on commit a4caba4

Please sign in to comment.