From 5196ace15896a7f879c238f971245035ec4ec973 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.php | 5 ++--- src/Reference/HasMany.php | 8 ++++---- src/Reference/HasOneSql.php | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Reference.php b/src/Reference.php index 913114f20..f8b4595fc 100644 --- a/src/Reference.php +++ b/src/Reference.php @@ -90,7 +90,7 @@ public function __construct($link) public function init(): void { $this->_init(); - + $this->initTableAlias(); } @@ -132,8 +132,7 @@ public function getTheirModel($defaults = []): Model if ($this->model instanceof \Closure) { // if model is Closure, then call the closure and whci should return a model $theirModel = ($this->model)($this->getOurModel(), $this, $defaults); - } - else { + } else { // if model is set, then use clone of this model $theirModel = clone $this->model; } diff --git a/src/Reference/HasMany.php b/src/Reference/HasMany.php index ab30b8145..1905b3747 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 ccf6d39f5..008fc6b84 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\'])'))