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 edf81f1
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 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 All @@ -63,7 +55,7 @@ abstract class Join
*
* If you are using the following syntax:
*
* $user->join('contact', 'default_contact_id');
* $user->join('contact', 'default_contact_id')
*
* Then the ID connecting tables is stored in foreign table and the order
* of saving and delete needs to be reversed. In this case $reverse
Expand All @@ -74,18 +66,16 @@ abstract class Join
protected $reverse;

/**
* Field to be used for matching inside master table. By default
* it's $foreign_table.'_id'.
* Note that it should be actual field name in master table.
* Field to be used for matching inside master table.
* By default it's $foreign_table.'_id'.
*
* @var string
*/
protected $master_field;

/**
* Field to be used for matching in a foreign table. By default
* it's 'id'.
* Note that it should be actual field name in foreign table.
* Field to be used for matching in a foreign table.
* By default it's 'id'.
*
* @var string
*/
Expand Down Expand Up @@ -240,7 +230,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 +351,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 edf81f1

Please sign in to comment.