Skip to content

Instantly share code, notes, and snippets.

@resistorsoftware
Created May 31, 2011 17:55
Show Gist options
  • Save resistorsoftware/1000968 to your computer and use it in GitHub Desktop.
Save resistorsoftware/1000968 to your computer and use it in GitHub Desktop.
how to write AR query to just show orders with a delivery date for an item
class UnfulfilledOrder < ActiveRecord::Base
belongs_to :shop
has_many :items, :dependent => :delete_all
end
class Item < ActiveRecord::Base
belongs_to :unfulfilled_orders
has_many :deliveries, :dependent => :delete_all
end
class Delivery < ActiveRecord::Base
belongs_to :items
def self.has_delivery? date
find_by_delivery_date(date)
end
def self.current date
where("delivery_date = ? ", date)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment