Skip to content

Commit

Permalink
fix: add singularAlias param on associations hasMany (#980)
Browse files Browse the repository at this point in the history
Fix singularized variable name in template
  • Loading branch information
arodu committed Mar 11, 2024
1 parent 0c7f444 commit 63ae641
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion templates/bake/Template/view.twig
Expand Up @@ -118,7 +118,7 @@
{% endif %}
{% set relations = associations.BelongsToMany|merge(associations.HasMany) %}
{% for alias, details in relations %}
{% set otherSingularVar = alias|variable %}
{% set otherSingularVar = alias|singularize|variable %}
{% set otherPluralHumanName = details.controller|underscore|humanize %}
<div class="related">
<h4><?= __('Related {{ otherPluralHumanName }}') ?></h4>
Expand Down
18 changes: 9 additions & 9 deletions tests/comparisons/Template/testBakeView.php
Expand Up @@ -74,17 +74,17 @@
<th><?= __('Published') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
<?php foreach ($author->articles as $articles) : ?>
<?php foreach ($author->articles as $article) : ?>
<tr>
<td><?= h($articles->id) ?></td>
<td><?= h($articles->author_id) ?></td>
<td><?= h($articles->title) ?></td>
<td><?= h($articles->body) ?></td>
<td><?= h($articles->published) ?></td>
<td><?= h($article->id) ?></td>
<td><?= h($article->author_id) ?></td>
<td><?= h($article->title) ?></td>
<td><?= h($article->body) ?></td>
<td><?= h($article->published) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['controller' => 'Articles', 'action' => 'view', $articles->id]) ?>
<?= $this->Html->link(__('Edit'), ['controller' => 'Articles', 'action' => 'edit', $articles->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['controller' => 'Articles', 'action' => 'delete', $articles->id], ['confirm' => __('Are you sure you want to delete # {0}?', $articles->id)]) ?>
<?= $this->Html->link(__('View'), ['controller' => 'Articles', 'action' => 'view', $article->id]) ?>
<?= $this->Html->link(__('Edit'), ['controller' => 'Articles', 'action' => 'edit', $article->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['controller' => 'Articles', 'action' => 'delete', $article->id], ['confirm' => __('Are you sure you want to delete # {0}?', $article->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
Expand Down

0 comments on commit 63ae641

Please sign in to comment.