Created
December 19, 2012 23:39
-
-
Save sweatpantsninja/4341731 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
belongs_to :order | |
belongs_to :item | |
validate :item_has_not_been_sent? | |
def user | |
self.order.user | |
end | |
def item_has_not_been_sent? | |
matching_order_items = user.order_items.where(:item_id => self.item_id).where(:size => self.size) | |
matching_order_items = matching_order_items.where{id != self.id} unless new_record? | |
if matching_order_items.exists? | |
errors.add(:item_id, "This item has already been sent to this user") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment