Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add singularAlias param on associations hasMany #980

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Utility/Model/AssociationFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function filterAssociations(Table $model): array
'displayField' => $target->getDisplayField(),
'foreignKey' => $assoc->getForeignKey(),
'alias' => $alias,
'singular' => Inflector::singularize($assocName),
'controller' => $className,
'fields' => $target->getSchema()->columns(),
'navLink' => $navLink,
Expand Down
2 changes: 1 addition & 1 deletion templates/bake/Template/view.twig
Original file line number Diff line number Diff line change
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 = details.singular|variable %}
arodu marked this conversation as resolved.
Show resolved Hide resolved
{% set otherPluralHumanName = details.controller|underscore|humanize %}
<div class="related">
<h4><?= __('Related {{ otherPluralHumanName }}') ?></h4>
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/Command/TemplateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ public function testGetContentAssociations()
'displayField' => 'name',
'foreignKey' => 'author_id',
'alias' => 'Authors',
'singular' => 'Author',
'controller' => 'TemplateTaskAuthors',
'fields' => ['name'],
],
Expand Down
18 changes: 9 additions & 9 deletions tests/comparisons/Template/testBakeView.php
Original file line number Diff line number Diff line change
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
Loading