Skip to content

Commit

Permalink
join persistence is determined by joined model
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 21, 2022
1 parent 0d38d46 commit 501eac2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 21 deletions.
19 changes: 4 additions & 15 deletions src/Model/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Atk4\Data\Exception;
use Atk4\Data\Field;
use Atk4\Data\Model;
use Atk4\Data\Persistence;
use Atk4\Data\Reference;

/**
Expand All @@ -37,20 +36,10 @@ abstract class Join
*/
protected $foreign_table;

/**
* If $persistence is set, then it's used for loading
* and storing the values, instead $owner->persistence.
*
* @var Persistence|Persistence\Sql|null
*/
protected $persistence;

/**
* Field that is used as native "ID" in the foreign table.
* When deleting record, this field will be conditioned.
*
* ->where($join->id_field, $join->id)->delete();
*
* @var string
*/
protected $id_field = 'id';
Expand All @@ -64,7 +53,7 @@ abstract class Join
*/
protected $kind;

/** @var bool Is our join weak? Weak join will stop you from touching foreign table. */
/** @var bool Weak join does not update foreign table. */
protected $weak = false;

/**
Expand All @@ -74,7 +63,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 Down Expand Up @@ -541,7 +530,7 @@ public function beforeInsert(Model $entity, array &$data): void
$data[$this->master_field] = $this->getId($entity);
}

// $entity->set($this->master_field, $this->getId($entity));
// $entity->set($this->master_field, $this->getId($entity)); // TODO needed? from array persistence
}

public function afterInsert(Model $entity): void
Expand All @@ -550,7 +539,7 @@ public function afterInsert(Model $entity): void
return;
}

$this->setSaveBufferValue($entity, $this->foreign_field, $this->hasJoin() ? $this->getJoin()->getId($entity) : $entity->getId()); // from array persistence...
$this->setSaveBufferValue($entity, $this->foreign_field, $this->hasJoin() ? $this->getJoin()->getId($entity) : $entity->getId()); // TODO needed? from array persistence

$foreignModel = $this->getForeignModel();
$foreignEntity = $foreignModel->createEntity()
Expand Down
3 changes: 0 additions & 3 deletions src/Persistence/Array_/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
use Atk4\Data\Model;
use Atk4\Data\Persistence;

/**
* @property Persistence\Array_|null $persistence
*/
class Join extends Model\Join
{
public function afterLoad(Model $entity): void
Expand Down
3 changes: 0 additions & 3 deletions src/Persistence/Sql/Join.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
use Atk4\Data\Model;
use Atk4\Data\Persistence;

/**
* @property Persistence\Sql $persistence
*/
class Join extends Model\Join
{
/**
Expand Down

0 comments on commit 501eac2

Please sign in to comment.