2
@orders.closed_today
是今天关闭的所有订单的数组。Rails从所有订单中获取所有项目
我该如何列出所有这些项目?
即@items = @orders.closed_today.items
更新 报告HTML
<% @items = Item.in_orders(@orders.closed_today) %>
项目模型
scope :in_orders, lambda { |orders| where('order_id is in (?)', orders.map(&:id).join(',')) }
这种类型的工作。需要将结果展平为单个[]。在http://stackoverflow.com/questions/4307411/not-in-rails中的某处,我可以搜索Item.order_id是否在@ orders.closed_today中。当试图在链接答案得到了一个SQLite3 :: SQLException:近“in”:语法错误:更新的问题,以显示我试过。 – pcasa 2011-03-27 20:27:16
使用订单上的范围添加项目的范围;这更多的是你要找的,对吗? – 20man 2011-03-27 22:58:51
将范围转为lambda以灵活使用范围日期范围。谢谢! – pcasa 2011-03-28 00:01:43