From ef2a32be4c7218764a29f099385198eb35eb127d Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 18 Mar 2013 22:01:08 +0800 Subject: [PATCH] Fix query for multi categories and tags --- app/controllers/pages_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index e9dd1b7b0..14d436f5f 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -71,12 +71,12 @@ class PagesController < ApplicationController else module_app = ModuleApp.first(:conditions => {:key => params[:app_name]}) if !params[:category_id].blank? && !params[:tag_id].blank? - @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => params[:tag_id]}) - @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category => params[:category_id], :tag => ''}) unless @item + @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category.in => params[:category_id], :tag.in => params[:tag_id]}) + @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category.in => params[:category_id], :tag => ''}) unless @item elsif !params[:category_id].blank? - @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], category: params[:category_id]).any_in(tag: [nil,'']).first + @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], :category.in => params[:category_id]).any_in(tag: [nil,'']).first elsif !params[:tag_id].blank? - @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], tag: params[:tag_id]).any_in(category: [nil,'']).first + @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action], :tag.in => params[:tag_id]).any_in(category: [nil,'']).first end @item = Item.find(params[:orig_page]) unless @item || params[:orig_page].blank? @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first unless @item