This project is archived and is in readonly mode.
Use accepts_nested_attributes_for with inverse_of cause infinite loop
Reported by Stephan Kaag | February 18th, 2011 @ 03:12 PM
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
Comments and changes to this ticket
-
Jeff Kreeftmeijer February 26th, 2011 @ 12:35 PM
- Importance changed from to Low
Hi Stefan,
I cleaned up your code block. Be sure to use a break after the starting the block with
@@@
:@@@ # code goes here @@@
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>