public withPersistence ( |
||
$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;
}