Skip to content

ContainsMany does not fire ref model hook when set or save  #881

@ibelar

Description

@ibelar

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions