Fix query for multi categories and tags (empty array)

This commit is contained in:
chris 2013-03-19 15:10:31 +08:00
parent ef2a32be4c
commit 7dcea95dd4
1 changed files with 4 additions and 4 deletions

View File

@ -72,14 +72,14 @@ class PagesController < ApplicationController
module_app = ModuleApp.first(:conditions => {:key => params[:app_name]}) module_app = ModuleApp.first(:conditions => {:key => params[:app_name]})
if !params[:category_id].blank? && !params[:tag_id].blank? 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.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.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 @item = Item.first(:conditions => {:module_app_id => module_app.id, :app_frontend_url => params[:app_action], :category.in => params[:category_id], :tag.in => [nil, []]}) unless @item
elsif !params[:category_id].blank? elsif !params[:category_id].blank?
@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 @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? elsif !params[:tag_id].blank?
@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 @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 end
@item = Item.find(params[:orig_page]) unless @item || params[:orig_page].blank? @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 @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
@item = Item.where(module_app_id: module_app.id, app_frontend_url: 'default_widget').first unless @item @item = Item.where(module_app_id: module_app.id, app_frontend_url: 'default_widget').first unless @item
@item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).first unless @item @item = Item.where(module_app_id: module_app.id, app_frontend_url: params[:app_action]).first unless @item
end end