Skip to content

Loading…

has_one polymorphic is creating circular dependency with parent model #1075

Closed
lighthouse-import opened this Issue · 1 comment

1 participant

@lighthouse-import

Imported from Lighthouse. Original ticket at: http://rails.lighthouseapp.com/projects/8994/tickets/6761
Created by Gabriel Mazetto - 2011-05-02 04:49:47 UTC

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".

@lighthouse-import

Imported from Lighthouse.
Comment by Gabriel Mazetto - 2011-05-02 04:52:57 UTC

Also forget to mention that it's rails 3.0.7

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.