public wherePrimary ( $key ) : self | ||
return | self |
public function wherePrimary($key)
{
if (is_array($this->primary) && Nette\Utils\Arrays::isList($key)) {
if (isset($key[0]) && is_array($key[0])) {
$this->where($this->primary, $key);
} else {
foreach ($this->primary as $i => $primary) {
$this->where($this->name . '.' . $primary, $key[$i]);
}
}
} elseif (is_array($key) && !Nette\Utils\Arrays::isList($key)) {
// key contains column names
$this->where($key);
} else {
$this->where($this->name . '.' . $this->getPrimary(), $key);
}
return $this;
}
/** * Default form handler */ public function process() { /** @var ArrayHash $values */ $values = $this->values; try { $this->onBeforeProcess($this, $values); if (isset($values->id)) { $this->onBeforeUpdate($this, $values); $arr = (array) $values; unset($arr['id']); $row = $this->selection->wherePrimary($values->id)->fetch(); $row->update($arr); $this->onAfterUpdate($row, $this, $values); } else { $this->onBeforeInsert($this, $values); $row = $this->selection->insert($values); $this->onAfterInsert($row, $this, $values); } $this->onAfterProcess($row, $this, $values); } catch (\PDOException $e) { $this->addError($e->getMessage()); dump($e); Debugger::log($e); } }