Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Use accepts_nested_attributes_for with inverse_of cause infinite loop #855

Closed
lighthouse-import opened this Issue · 2 comments

1 participant

@lighthouse-import

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
@lighthouse-import

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

@lighthouse-import

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.