@tasks = Task.find(:all, :conditions => [ 'complete = ?', false ])
@task = Task.find(:first, :conditions => [ 'complete = ?', false ], :order => 'created_at DESC')
以动态的find_by和find_all_by方法缩短查询语句,以下代码等效。
@tasks = Task.find_all_by_complete(false)
@task = Task.find_by_complete(false, :order => 'created_at DESC')
另外
1.对于:conditons后面有2个参数的情况,下面的代码等效。
Task.find(:all, :conditions => [ 'complete = ? AND category_id = ?', false, 1 ])
Task.find_all_by_complete_and_category_id(false, 1)
2.动态查询支持nil, array以及range作为参数。看源代码有下面一段:
def attribute_condition(argument)
case argument
when nil then "IS ?"
when Array then "IN (?)"
when Range then "BETWEEN ? AND ?"
else "= ?"
end
end
于是,如果想要查询上海或者北京,18到30岁的用户,可以这么写
User.find_all_by_city_and_age([ 'Shanghai', 'Beijing' ], 18..30)
3.动态查询仍然可以使用:conditions参数,额外的条件会使用with_scope来约束。
Book.find_by_title('title', :conditions => ['price > ?', price])
分享到:
相关推荐
#define CONFIG_FIND_BEST_CHANNEL 1 #endif #define CONFIG_SKB_COPY 1//for amsdu #define CONFIG_LED #ifdef CONFIG_LED #define CONFIG_SW_LED #ifdef CONFIG_SW_LED //#define CONFIG_LED_HANDLED_BY_CMD...
内存加载动态库 MemoryLoadLibrary 有例子。 /* * Memory DLL loading code * Version 0.0.3 * * Copyright (c) 2004-2013 by Joachim Bauch / mail@joachim-bauch.de * http://www.joachim-bauch.de * * ...
实现网页的键盘输入操作 from selenium.webdriver.common...#find_element_by_class_name可以是find_element_by_link_text、find_element_by_id等其他方式 #send_keys一些特殊字符串,可以通过help(Keys)显示出来,如实
在science上的一篇非常简单高效的聚类算法
intel graphics hd 630显卡已有硬件解码功能,linux平台下如何使用硬件解码呢?1.安装ffmpeg2.安装显卡驱动3.编译hw_decode.c #gcc -o hw_decode hw_decode.c -I/.../include -L/.../lib -lavformat -lavfilter -...
用过houdini 和 nuke 的小伙伴,肯定都使用过快速输入命令菜单,只要输入几个字符,即可显示相关的命令列表。 而maya中却没有此类工具插件。有时突然忘了命令的位置,想找就很麻烦。那么通过这个插件就可以快速查找...
r18_ap6330的步骤.txt 2017/2/9 10:47 开始整理 原始SDK默认配置为rtl8723bs,现在要修改为:AP6330。 硬件平台:全志R18。 开发板:DP-18 SDK:Android6.0.1/Linux3.10.65(v2.1版本,发布日期20161008) ...
find pid by name for linux Interface Driver.
driver.find_element_by_id() # id定位 driver.find_element_by_name() # name定位 driver.find_element_by_class_name() # class名称定位 driver.find_element_by_tag_name() # 标签定位 driver.find_element_...
LLE also begins by finding a set of the nearest neighbors of each point. It then computes a set of weights for each point that best describe the point as a linear combination of its neighbors. ...
Clustering by fast search and find of density peaks的matlab实现代码的有注释版本,带有一个测试数据集,可以用来学习参考。
Matlab2015B- cracking software abroad website down very hard to findFile
// We use the CSubclassWnd class, created by William E. Kempf (sirwillard@my-Deja.com) // You can find the complete article at http://www.codeproject.com/miscctrl/subclasswnd.asp #include "SubclassWnd...
# $(call find-copy-subdir-files,*,device/softwinner/polaris-common/rild/usb_modeswitch.d,system/etc/usb_modeswitch.d) PRODUCT_PROPERTY_OVERRIDES += \ ro.sw.embeded.telephony = false PRODUCT_...
# $(call find-copy-subdir-files,*,device/softwinner/polaris-common/rild/usb_modeswitch.d,system/etc/usb_modeswitch.d) PRODUCT_PROPERTY_OVERRIDES += \ ro.sw.embeded.telephony = false PRODUCT_...
# it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 of the License. # # This program is distributed in the hope that it will be useful, # ...
科学杂志:Clustering by fast search and find of density peaks Clustering by fast search and find of density peaks
You can find the complete tutorial at the following address: http://www.lowagie.com/iText/tutorial/ This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY without ...
本文章来为各位介绍一篇...order by find_in_set( id, '783, 769, 814, 1577, 1769' ) 查出来: 769 1577 814 1769 783 为什么不是 783 769 814 1577 1769 的顺序? 注意:经查找后原因出在find_in_set里面,如果f
@FindBy