Skip to content

Commit

Permalink
[update] remove unnecessary check for id_field
Browse files Browse the repository at this point in the history
  • Loading branch information
georgehristov committed Jul 26, 2020
1 parent 6156ae2 commit 5196ace
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions src/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function __construct($link)
public function init(): void
{
$this->_init();

$this->initTableAlias();
}

Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Reference/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}

Expand All @@ -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);
}

/**
Expand All @@ -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()
);
}
Expand All @@ -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()
);

Expand Down
2 changes: 1 addition & 1 deletion src/Reference/HasOneSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -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\'])'))
Expand Down

0 comments on commit 5196ace

Please sign in to comment.