Skip to content

Commit

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

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

Expand All @@ -73,9 +73,10 @@ private function getLinkNameWithoutReferenceSuffix(): string

private function getOurFieldCaptionWithoutReferenceSuffix(Model $theirModel): string
{
$ourModel = $this->getOurModel();
$theirField = $theirModel->getField($this->getTheirFieldName($theirModel));

return preg_replace('~ (' . preg_quote($theirField->getCaption(), '~') . '|ID)$~i', '', $this->getOurField()->getCaption());
return preg_replace('~ (' . preg_quote($theirField->getCaption(), '~') . '|' . preg_quote($ourModel->getIdField()->getCaption(), '~') . '|ID)$~i', '', $this->getOurField()->getCaption());
}

/**
Expand Down Expand Up @@ -181,7 +182,7 @@ public function refLink(array $defaults = []): Model
*/
public function addTitle(array $defaults = []): SqlExpressionField
{
$fieldName = $defaults['field'] ?? $this->getLinkNameWithoutReferenceSuffix();
$fieldName = $defaults['field'] ?? $this->getLinkNameWithoutIdSuffix();

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

Expand Down

0 comments on commit 865ff24

Please sign in to comment.