From b2c69db4e531d41b269f77b91ee8c69ec2dd7542 Mon Sep 17 00:00:00 2001 From: Georgi Hristov Date: Sun, 26 Jul 2020 11:18:36 +0200 Subject: [PATCH] [update] remove unnecessary check for id_field --- src/Reference/HasMany.php | 8 ++++---- src/Reference/HasOneSql.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Reference/HasMany.php b/src/Reference/HasMany.php index ab30b81457..1905b3747b 100644 --- a/src/Reference/HasMany.php +++ b/src/Reference/HasMany.php @@ -31,7 +31,7 @@ protected function getOurValue() // create expression based on existing conditions return $ourModel->action('field', [ - $this->our_field ?: ($ourModel->id_field ?: 'id'), + $this->our_field ?: $ourModel->id_field, ]); } @@ -44,7 +44,7 @@ protected function referenceOurValue(): Field $ourModel->persistence_data['use_table_prefixes'] = true; - return $ourModel->getField($this->our_field ?: ($ourModel->id_field ?: 'id')); + return $ourModel->getField($this->our_field ?: $ourModel->id_field); } /** @@ -57,7 +57,7 @@ public function ref($defaults = []): Model $ourModel = $this->getOurModel(); return $this->getTheirModel($defaults)->addCondition( - $this->their_field ?: ($ourModel->table . '_' . ($ourModel->id_field ?: 'id')), + $this->their_field ?: ($ourModel->table . '_' . $ourModel->id_field), $this->getOurValue() ); } @@ -72,7 +72,7 @@ public function refLink($defaults = []): Model $ourModel = $this->getOurModel(); $theirModelLinked = $this->getTheirModel($defaults)->addCondition( - $this->their_field ?: ($ourModel->table . '_' . ($ourModel->id_field ?: 'id')), + $this->their_field ?: ($ourModel->table . '_' . $ourModel->id_field), $this->referenceOurValue() ); diff --git a/src/Reference/HasOneSql.php b/src/Reference/HasOneSql.php index ccf6d39f50..008fc6b84b 100644 --- a/src/Reference/HasOneSql.php +++ b/src/Reference/HasOneSql.php @@ -191,7 +191,7 @@ public function addTitle($defaults = []): FieldSqlExpression $ourModel = $this->getOurModel(); - $field = $defaults['field'] ?? preg_replace('/_' . ($ourModel->id_field ?: 'id') . '$/i', '', $this->link); + $field = $defaults['field'] ?? preg_replace('/_' . $ourModel->id_field . '$/i', '', $this->link); if ($ourModel->hasField($field)) { throw (new Exception('Field with this name already exists. Please set title field name manually addTitle([\'field\'=>\'field_name\'])'))