This project is archived and is in readonly mode.

#6761 new
Gabriel Mazetto

has_one polymorphic is creating circular dependency with parent model

Reported by Gabriel Mazetto | May 2nd, 2011 @ 05:49 AM

Use this two models:

class Item < ActiveRecord::Base
belongs_to :itemable, :polymorphic => true end

class Product < ActiveRecord::Base
has_one :item, :as => :itemable, :dependent => destroy accepts_nested_attributes_for :item end

now try to:

@product =[:product]) @product.build_item(params[:item]) @product.valid?

And you will get a error lacking the "item.itemable_id"

So, build_item is defining the correct itemable_type, but are not dealing with the id... I expect it to save "course" first, get it's id and them set it on itemable_id and then save "item".

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=""></a>

People watching this ticket