setDb($db); $this->setTableAlias($tableAlias); } protected function setDb(Zend_Db_Adapter_Pdo_Mysql $db) { $this->db = $db; return $this; } public function find(array $key) { return $this->getTable()->searchBy($key); } public function isUnique($field, $value, array $key = []) { $select = $this->db->select(); $select->from(Qs_Db::getPair($this->tableAlias), new Zend_Db_Expr('1')); $select->where('`' . $field . '` = ?', $value); if ($key) { foreach ($key as $field => $value) { if (is_null($value)) { $select->where("`{$field}` IS NOT NULL"); } else { $select->where("`{$field}` != ?", $value); } } } $select->limit(1); return '1' !== $this->db->fetchOne($select); } }