Skip to content

Commit

Permalink
no Join::id_field
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 21, 2022
1 parent 501eac2 commit 8fdaf25
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions src/Model/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8fdaf25

Please sign in to comment.