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.

has_one polymorphic is creating circular dependency with parent model

#6761

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.new(params[: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".

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

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

Activity

  1. Gabriel Mazetto
    Gabriel Mazetto

    Also forget to mention that it's rails 3.0.7

    May 2nd, 2011 @ 05:52 AM