我正在尝试使用reasons
找到所有type_id = 3
个对象:
使用ActiveRecord,我希望查询为:
reasons = Reason.where('type_id = 3')
然后我可以用以下方法遍历每个原因:
reasons.each do |reason|
# do stuff with the reason...
end
答案 0 :(得分:0)
对于更简单的查询,您可以使用支持缩写语法的新过滤器选项:
reasons = Reason.all().filter(type_id=3)
for reason in reasons:
# do stuff with reason
对于更高级的查询,您可以使用查询语法:
from orb import Query as Q
reasons = Reason.select(where=Q('type_id') == 3)
for reason in reasons:
# do stuff with reason