Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Use accepts_nested_attributes_for with inverse_of cause infinite loop

#6449
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

Reported by Stephan Kaag · February 18th, 2011 @ 03:12 PM

State: new
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Jeff Kreeftmeijer
    Jeff Kreeftmeijer
    • 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
     @@@
    

    February 26th, 2011 @ 12:35 PM

  2. pechorin-andrey
    pechorin-andrey

    same error on 3.0.7 with 1.8.7 mri

    April 26th, 2011 @ 03:28 PM