atk4\data\Model::withPersistence PHP Method

withPersistence() public method

If you specify $id then it will be used to save/update your record. If set $id to true then model will assume that there is already record like that in the destination persistence. If you wish to fully copy the data from one model to another you should use: $m->withPersintence($p2, false)->set($m)->save(); See https://github.com/atk4/data/issues/111 for use-case examples.
public withPersistence ( Persistence $persistence, mixed $id = null, string $class = null )
$persistence Persistence
$id mixed
$class string
    public function withPersistence($persistence, $id = null, string $class = null)
    {
        if (!$persistence instanceof \atk4\data\Persistence) {
            throw new Exception(['Please supply valid persistence', 'arg' => $persistence]);
        }
        $m = new $class($persistence);
        if ($id === true) {
            $m->id = $this->id;
            $m[$m->id_field] = $this[$this->id_field];
        } elseif ($id) {
            $m->id = null;
            // record shouldn't exist yet
            $m[$m->id_field] = $id;
        }
        $m->data = $this->data;
        $m->dirty = $this->dirty;
        return $m;
    }