Skip to content

Instantly share code, notes, and snippets.

@arbarlow
Created May 26, 2011 14:40
Show Gist options
  • Save arbarlow/993283 to your computer and use it in GitHub Desktop.
Save arbarlow/993283 to your computer and use it in GitHub Desktop.
class Order < ActiveRecord::Base
has_many :order_products
validates_associated :order_products # This checks all the order_product instances are valid
end
class OrderProduct < ActiveRecord::Base
belongs_to :order
belongs_to :product
validates :order, :product, :presence => true
end
class Product < ActiveRecord::Base
has_many :order_products
validates :name, :description, :price, :presence => true
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment