Use accepts_nested_attributes_for with inverse_of cause infinite loop #855

Closed
lighthouse-import opened this Issue May 16, 2011 · 2 comments

Comments

Projects
None yet
1 participant

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6449
Created by Stephan Kaag - 2011-02-26 12:10:12 UTC

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

Imported from Lighthouse.
Comment by Jeff Kreeftmeijer - 2011-02-26 12:35:31 UTC

Hi Stefan,

I cleaned up your code block. Be sure to use a break after the starting the block with `````:

code goes here

Imported from Lighthouse.
Comment by pechorin-andrey - 2011-04-26 14:28:35 UTC

same error on 3.0.7 with 1.8.7 mri

hisas pushed a commit to hisas/rails that referenced this issue May 9, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment