Reputation: 1
I have two tables: shipments and manifests.
A Shipment has_many Manifests, and a Manifest belongs_to one Shipment.
How do I write an ActiveRecord scope that returns me all the Shipments where:
Upvotes: 0
Views: 262
Reputation: 8408
Hi I'm not sure if it can be achieved through scopes in ruby it may be sth like
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
Upvotes: 0