Skip to content

Instantly share code, notes, and snippets.

@stephankaag
Created February 18, 2011 15:14
Show Gist options
  • Save stephankaag/833798 to your computer and use it in GitHub Desktop.
Save stephankaag/833798 to your computer and use it in GitHub Desktop.
class Order < ActiveRecord::Base
has_many :order_items, :inverse_of => :order
accepts_nested_attributes_for :order_items
end
class OrderItem < ActiveRecord::Base
belongs_to :order, :inverse_of => :order_items
accepts_nested_attributes_for :order
end
> order = Order.new
=> #<Order id: nil, created_at: nil, updated_at: nil>
> order_item = OrderItem.new
=> #<OrderItem id: nil, order_id: nil, created_at: nil, updated_at: nil>
> order.order_items << order_item
=> [#<OrderItem id: nil, order_id: nil, created_at: nil, updated_at: nil>]
> order.valid?
SystemStackError: stack level too deep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment