-
Notifications
You must be signed in to change notification settings - Fork 48
ContainsMany does not fire ref model hook when set or save #881
Copy link
Copy link
Closed
Labels
Description
Consider code below:
class Client extends \Atk4\Data\Model
{
public $table = 'client';
public $caption = 'Client';
protected function init(): void
{
parent::init();
$this->addField('name');
$this->containsMany('Accounts', ['model' => [Account::class]]);
}
}
class Account extends \Atk4\Data\Model
{
public $caption = ' ';
protected function init(): void
{
parent::init();
$this->addField('email', [
'required' => true,
'ui' => ['multiline' => [Multiline::INPUT => ['icon' => 'envelope', 'type' => 'email']]],
]);
}
}
When changing Accounts reference value, then the Account model hook should be fire. Actually id does not.
Ex:
$m = new Client($app->db);
// loading client that has 3 related account record.
$clientEntity = $m->load(6);
$ac = $clientEntity->get('Accounts');
array_pop($ac);
$clientEntity->set('Accounts', $ac);
$clientEntity->save();
Then, when setting Account or saving Client, the Account model hook should be fired.
Reactions are currently unavailable