社区里面讨论过 or 的写法,现在终于 Rails 5 出了官方的解法,考虑到很大一部分同学要用上 Rails 5 起码还有半年,今天我在bf4 的一个帖子的基础上,做了一个 gems : where-or
总之,终于可以这样写 or 了。
post = Post.where('id = 1').or(Post.where('id = 2'))
或者是一个产品级(也就是写的很差的意思,欢迎大家帮我重写^_^)的用法?
@rms_tool_recipe = Ref::ToolRecipe.all
@lot_recipes.collect(&:recipe).reject { |v| v.length < 3 }
.collect { |r| r.start_with?('Q') ? 'P' + r[1..-1] : r }.each do |r|
@rms_tool_recipe = @rms_tool_recipe.or(Ref::ToolRecipe.where('recipe_id LIKE :r', r: "%#{r}"))
end
@rms_tool_recipe = @rms_tool_recipe.where(golden_flag: 1, recipe_category: 'PROD').select('recipe_id')
Rails.logger.info "@rms_tool_recipe: #{@rms_tool_recipe.to_sql}"
@rms_tool_recipe: SELECT "EES_RMS_TOOL_RECIPE"."RECIPE_ID" FROM "EES_RMS_TOOL_RECIPE" WHERE ((((((((((((((((recipe_id LIKE '%P12-150MI') OR (recipe_id LIKE '%P12457-20NI150MI')) OR (recipe_id LIKE '%P12457-20NI150MI')) OR (recipe_id LIKE '%P12457-785X11982-20NI110')) OR (recipe_id LIKE '%1Ynm-785X11982-457um')) OR (recipe_id LIKE '%PULGA-03852')) OR (recipe_id LIKE '%P039441NI00-457(L)')) OR (recipe_id LIKE '%PATN 9 High pressure oven')) OR (recipe_id LIKE '%1 / 3')) OR (recipe_id LIKE '%P03944-1')) OR (recipe_id LIKE '%P03944-00217')) OR (recipe_id LIKE '%P-01322-01258-14X18-0.4X0.4')) OR (recipe_id LIKE '%SDSS Pre-con Pb-Free')) OR (recipe_id LIKE '%SDSS Pre-con Pb-Free')) OR (recipe_id LIKE '%P-ULGA-14X18-03131')) OR (recipe_id LIKE '%TBD')) AND "EES_RMS_TOOL_RECIPE"."GOLDEN_FLAG" = '1' AND "EES_RMS_TOOL_RECIPE"."RECIPE_CATEGORY" = 'PROD'