atk4\data\Persistence::add PHP Method

add() public method

Associate model with the data driver.
public add ( Model | string $m, array $defaults = [] ) : Model
$m Model | string Model which will use this persistence
$defaults array Properties
return Model
    public function add($m, $defaults = [])
    {
        if (isset($defaults[0])) {
            $m->table = $defaults[0];
            unset($defaults[0]);
        }
        $m = $this->factory($m, $defaults);
        if ($m->persistence) {
            if ($m->persistence === $this) {
                return $m;
            }
            throw new Exception(['Model is already related to another persistence']);
        }
        $m->setDefaults($defaults);
        $m->persistence = $this;
        $m->persistence_data = [];
        $this->initPersistence($m);
        $m = $this->_add($m, $defaults);
        $this->hook('afterAdd', [$m]);
        return $m;
    }