public function attach($id, $table)
{
if (!$this->isDetached) {
throw new InvalidStateException('Result is not in detached state.');
}
if ($this->connection === null) {
throw new InvalidStateException('Missing connection.');
}
if ($this->mapper === null) {
throw new InvalidStateException('Missing mapper.');
}
$modifiedData = $this->getModifiedData(self::DETACHED_ROW_ID);
$this->data = [$id => [$this->mapper->getPrimaryKey($table) => $id] + $modifiedData];
$this->modified = [];
$this->table = $table;
$this->isDetached = false;
}