public function where(array $criteria, $joinWithAnd = true,
            $notEqual = false, $valuesAreColumns = false) {
        if (count($criteria)) {
            if (!$this->where) {
                $this->where = ' WHERE (';
                $opened = true;
            }
//            else if ($this->where && substr($this->where,
//                            strlen($this->where) - 1) === ')')
//                    $this->where = substr($this->where, 0,
//                        strlen($this->where) - 1);

            if (substr($this->where, strlen($this->where) - 1) != '(') {
                $this->where .= $joinWithAnd ? ' AND ' : ' OR ';
            }
            foreach ($criteria as $ky => $row) {
                if ($ky) $this->where .= ' OR (';

                $rowArray = $this->checkModel($row);
                $cnt = 1;
                foreach ($rowArray as $column => $value) {
                    if (!is_array($value)) {
                        $this->where .= '`' . $this->name . '`.`' . Util::camelTo_($column) . '` ';
                        $this->where .= ($notEqual) ? '!=' : '=';
                        if ($valuesAreColumns)
                                $this->where .= '`' . $this->name . '`.`' . Util::camelTo_($value) . '` ';
                        else {
                            $this->where .= ' ?';
                            $this->values[] = $value;
                        }
                        if (count($rowArray) > $cnt) $this->where .= ' AND ';
                    }
                    else {
                        $this->where .= '`' . $this->name . '`.`' . Util::camelTo_($column) . '` ';
                        $this->where .= ($notEqual) ? 'NOT IN' : 'IN';
                        $this->where .= ' (';
                        if ($valuesAreColumns) {
                            $n = 0;
                            foreach ($value as $val) {
                                if ($n) $this->where .= ', ';
                                $this->where .= '`' . $this->name . '`.`' .
                                        Util::camelTo_($val) . '`';
                                $n++;
                            }
                        }
                        else {
                            $this->where .= '?' . str_repeat(',?',
                                            count($value) - 1);
                            $this->values = $this->values ? array_merge($this->values,
                                            $value) : $value;
                        }
                        $this->where .= ')';
                    }
                    $cnt++;
                }
                if ($opened) $this->where .= ')';
            }
        }
        return $this;
    }