/** * @param string|null $q * @param bool $collection * @return Lib_Model_Set * @throws Exception */ public function loadSet($q = null, $collection = false) { $q = $this->getSelect(); $pkey = $this->getPrimaryKey(); if (count($q->getPart('columns')) == 0) { $q->columns(['*']); } elseif (!$collection && !array_some($this->getColumns(), function ($arr) use($pkey) { return $pkey == zend_column_name($arr); })) { $this->setColumns($pkey); } $db = $this->getDb(); $this->preLoad(); try { $result = $db->fetchAll($q); } catch (Exception $e) { throw new Exception('Error while loading: ' . $e->getMessage() . ' | SQL: ' . $q->assemble()); } $this->postLoad(); $set = new Lib_Model_Set(); $set->setResultSet($result); $set->setModel($this); return $set; }
/** * Returns comparator for zend column $tableAlias AND $columnName * @param string|null $tableAlias * @param string|null $columnName * @return callable $zendColumnExpression => $isMatching */ function zend_column_eq_dg($tableAlias, $columnName) { return function ($descriptor) use($columnName, $tableAlias) { $colname = zend_column_name($descriptor); $tblalias = zend_column_table($descriptor); return $tblalias === $tableAlias && $colname === $columnName; }; }