我有两张桌子:货物和舱单。
装运has_many Manifest,Manifest属于一个装运。
如何编写ActiveRecord范围,将范围内的所有货件返回给我:
答案 0 :(得分:0)
嗨我不确定它是否可以通过ruby中的范围实现它可能会像......
shipments = Shipments.all( :include => :manifests )
empty_shipments = shipments.select { |item| item.manifests.blank? }
non_empty_shipments = shipments - empty_shipments
non_empty_shipments.delete_if {|item| (item.t_start..item.t_end).cover? Time.now}
empty_shipments & non_empty_shipments