atk4\data\Join_SQL::beforeInsert PHP Method

beforeInsert() public method

public beforeInsert ( $model, &$data )
    public function beforeInsert($model, &$data)
    {
        if ($this->weak) {
            return;
        }
        // The value for the master_field is set, so we are going to use existing record anyway
        if ($model->hasElement($this->master_field) && $model[$this->master_field]) {
            return;
        }
        $insert = $this->dsql();
        $insert->mode('insert');
        $insert->set($model->persistence->typecastSaveRow($model, $this->save_buffer));
        $this->save_buffer = [];
        $insert->set($this->foreign_field, null);
        $insert->insert();
        $this->id = $insert->connection->lastInsertID();
        if ($this->join) {
            $this->join->set($this->master_field, $this->id);
        } else {
            $data[$this->master_field] = $this->id;
        }
    }