atk4\data\Persistence_SQL::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 = [])
    {
        // Use our own classes for fields, references and expressions unless
        // $defaults specify them otherwise.
        $defaults = array_merge(['_default_class_addField' => $this->_default_class_addField, '_default_class_hasOne' => $this->_default_class_hasOne, '_default_class_hasMany' => $this->_default_class_hasMany, '_default_class_addExpression' => $this->_default_class_addExpression, '_default_class_join' => $this->_default_class_join], $defaults);
        $m = parent::add($m, $defaults);
        if (!isset($m->table) || !is_string($m->table) && $m->table !== false) {
            throw new Exception(['Property $table must be specified for a model', 'model' => $m]);
        }
        // When we work without table, we can't have any IDs
        if ($m->table === false) {
            $m->getElement('id')->destroy();
            $m->addExpression('id', '1');
        } else {
            // SQL databases use ID of int by default
            //$m->getElement('id')->type = 'integer';
        }
        return $m;
    }