This project is archived and is in readonly mode.

#6449 new
Stephan Kaag

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

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>

Pages