public function execute() { if (ArrayHelper::isEmpty(ArrayHelper::getValue($this->qb->getQueryParts(), 'select', null))) { $this->qb->select('*'); } if (ArrayHelper::isEmpty(ArrayHelper::getValue($this->qb->getQueryParts(), 'from', null))) { $this->qb->from($this->model->meta->dbTable); } return $this->qb->execute()->fetchAll(PDO::FETCH_ASSOC); }
/** * This method will try to update the model. If the model was updated (in the sense that an update query was done * and a matching row was found from the DB) the method will return True. * * @param $records * @param $pkValue * @param $forceUpdate * * @return bool|int * * @since 1.1.0 * * @author Eddilbert Macharia (http://eddmash.com) <*****@*****.**> */ private function doUpdate($records, $pkValue, $forceUpdate) { $filtered = $this->objects()->filter([$this->meta->primaryKey->name => $pkValue]); // We can end up here when saving a model in inheritance chain where // update_fields doesn't target any field in current model. In that // case we just say the update succeeded. Another case ending up here // is a model with just PK - in that case check that the PK still // exists. if (ArrayHelper::isEmpty($records)) { return $filtered->exists(); } if (!$forceUpdate) { // It may happen that the object is deleted from the DB right after // this check, causing the subsequent UPDATE to return zero matching // rows. The same result can occur in some rare cases when the // database returns zero despite the UPDATE being executed // successfully (a row is matched and updated). In order to // distinguish these two cases, the object's existence in the // database is again checked for if the UPDATE query returns 0. if ($filtered->exists()) { return $filtered->_update($records) || $filtered->exists(); } else { return false; } } return $filtered->_update($records); }