protected function _createWhereClause(array $query, $separator = 'AND', $useJointView = true) {
        $where = array();
        $adapter = $this->_model->getAdapter();
        $nativeColumns = $this->_model->info(Zend_Db_Table_Abstract::COLS);
        if ($useJointView) {
            $tableName = $this->_getTableName($this->_model);
            $mockTable = new Zend_Db_Table(
                array(
                Zend_Db_Table_Abstract::NAME => $tableName,
                Zend_Db_Table_Abstract::PRIMARY => $this->_model->info(
                    Zend_Db_Table_Abstract::PRIMARY
                ))
            );
            $nativeColumns = $mockTable->info(Zend_Db_Table_Abstract::COLS);
        } else {
            $tableName = $this->_model->getName();
        }

        // change native columns to lowercase
        // because when columnName is configured in camelcase in the model config
        // it causes problems when checking if refColumn is a native column
        $nativeColumns = array_map(
            function ($column) {
                return strtolower($column);
            }, $nativeColumns
        );

        foreach ($query as $column => $value) {
            if (strtoupper($column) === 'OR' && is_array($value)) {
                $where[] = $this->_createWhereClause($value, 'OR');
            } elseif (is_array($value)) {
                $where[] = $adapter->quoteInto(
                    $adapter->quoteIdentifier($tableName) . '.' . $column . ' IN(?)',
                    $value
                );
            } elseif (is_null($value)) {
                if (substr($column, -2) == '<>') {
                    $column = preg_replace('/<>$/', '', $column);
                    $where[] = $column . ' IS NOT NULL';
                } else {
                    $where[] = $column . ' IS NULL';
                }
            } elseif (is_scalar($value)) {
                // Use $refColumn to see if this column is native to the current
                // model.
                $refColumn = null;
                if (!preg_match('/(>=?|<=?|like|<>)/i', $column, $matches)) {
                    $refColumn = $column;
                    $column = $adapter->quoteIdentifier($column) . ' =';
                } else {
                    // explode column so the actual column name can be quoted
                    $parts = explode(' ', $column);
                    $refColumn = $parts[0];
                    $column = $adapter->quoteIdentifier($parts[0]) . ' ' . $parts[1];
                }

                if (strpos($refColumn, '.') === false && in_array($refColumn, $nativeColumns)) {
                    $column = $adapter->quoteIdentifier($tableName) . '.' . $column;
                }
                $where[] = $adapter->quoteInto($column . ' ?', $value);
            }
        }
        return '(' . implode(" $separator ", $where) . ')';
    }