function __construct($table, ORM $notORM, $single = false, $where = array()) { parent::__construct($table, $notORM, $single); if (array_key_exists($notORM->structure->getPrimary($table), $where)) { $this->access = array($notORM->structure->getPrimary($table) => true); $this->notORM->__updateRowClass($table); $id = $where[$notORM->structure->getPrimary($table)]; $this->rows = [$id => new $this->notORM->rowClass($where, $this)]; $this->data = $this->rows; } }
/** * Delete rowset * * @param NotORM_Result $rowset * @return integer Number of affected rows */ public function delete($rowset) { return $rowset->delete(); }
/** Delete row * @return int number of affected rows or false in case of an error */ function delete() { // delete is an SQL keyword $result = new NotORM_Result($this->result->table, $this->result->notORM); $return = $result->where($this->result->primary, $this->primary)->delete(); $this->primary = $this[$this->result->primary]; return $return; }
protected function execute() { if (!isset($this->rows)) { $referencing =& $this->result->referencing[$this->__toString()]; if (!isset($referencing)) { if (!$this->limit || count($this->result->rows) <= 1 || $this->union) { parent::execute(); } else { //! doesn't work with union $result = clone $this; $first = true; foreach ((array) $this->result->rows as $val) { if ($first) { $result->where[0] = "{$this->column} = " . $this->quote($val); $first = false; } else { $clone = clone $this; $clone->where[0] = "{$this->column} = " . $this->quote($val); $result->union($clone); } } $result->execute(); $this->rows = $result->rows; } $referencing = array(); foreach ($this->rows as $key => $row) { $referencing[$row[$this->column]][$key] = $row; } } $this->data =& $referencing[$this->active]; if (!isset($this->data)) { $this->data = array(); } } }
protected function execute() { if (!isset($this->rows)) { $referencing =& $this->result->referencing[$this->__toString()]; if (!isset($referencing)) { $limit = $this->limit; $rows = count($this->result->rows); if ($this->limit && $rows > 1) { $this->limit = null; } parent::execute(); $this->limit = $limit; $referencing = array(); $offset = array(); foreach ($this->rows as $key => $row) { $ref =& $referencing[$row[$this->column]]; $skip =& $offset[$row[$this->column]]; if (!isset($limit) || $rows <= 1 || count($ref) < $limit && $skip >= $this->offset) { $ref[$key] = $row; } else { unset($this->rows[$key]); } $skip++; unset($ref, $skip); } } $this->data =& $referencing[$this->active]; if (!isset($this->data)) { $this->data = array(); } } }