From 8fdaf25d460a468753afab6b25746e4814209c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Fri, 21 Jan 2022 14:36:38 +0100 Subject: [PATCH] no Join::id_field --- src/Model/Join.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/Model/Join.php b/src/Model/Join.php index 27ff859b22..c238bbf11a 100644 --- a/src/Model/Join.php +++ b/src/Model/Join.php @@ -36,14 +36,6 @@ abstract class Join */ protected $foreign_table; - /** - * Field that is used as native "ID" in the foreign table. - * When deleting record, this field will be conditioned. - * - * @var string - */ - protected $id_field = 'id'; - /** * By default this will be either "inner" (for strong) or "left" for weak joins. * You can specify your own type of join by passing ['kind' => 'right'] @@ -240,7 +232,7 @@ protected function init(): void if ($this->master_field && $this->master_field !== $id_field) { // TODO not implemented yet, see https://github.com/atk4/data/issues/803 throw (new Exception('Joining tables on non-id fields is not implemented yet')) ->addMoreInfo('master_field', $this->master_field) - ->addMoreInfo('id_field', $this->id_field); + ->addMoreInfo('id_field', $id_field); } if (!$this->master_field) { @@ -361,9 +353,10 @@ public function hasOne(string $link, array $defaults = []) */ public function hasMany(string $link, array $defaults = []) { + $id_field = $this->getOwner()->id_field; $defaults = array_merge([ - 'our_field' => $this->id_field, - 'their_field' => $this->getModelTableString($this->getOwner()) . '_' . $this->id_field, + 'our_field' => $id_field, + 'their_field' => $this->getModelTableString($this->getOwner()) . '_' . $id_field, ], $defaults); return $this->getOwner()->hasMany($link, $defaults);