Skip to content

Commit

Permalink
unify suffix guessing
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 11, 2025
1 parent d639bc9 commit 8ec0ba0
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Reference/HasOneSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ private function _addField(string $fieldName, bool $theirFieldIsTitle, ?string $
return $fieldExpression;
}

private function getLinkNameWithoutReferenceSuffix(): string
{
$ourModel = $this->getOurModel();

return preg_replace('~_(' . preg_quote($ourModel->idField, '~') . '|id)$~', '', $this->link);
}

private function getOurFieldCaptionWithoutReferenceSuffix(Model $theirModel): string
{
$theirField = $theirModel->getField($this->getTheirFieldName($theirModel));
Expand Down Expand Up @@ -174,9 +181,7 @@ public function refLink(array $defaults = []): Model
*/
public function addTitle(array $defaults = []): SqlExpressionField
{
$ourModel = $this->getOurModel();

$fieldName = $defaults['field'] ?? preg_replace('~_(' . preg_quote($ourModel->idField, '~') . '|id)$~', '', $this->link);
$fieldName = $defaults['field'] ?? $this->getLinkNameWithoutReferenceSuffix();

$defaults['ui'] = array_merge(['visible' => true], $defaults['ui'] ?? [], ['editable' => false]);

Expand Down

0 comments on commit 8ec0ba0

Please sign in to comment.