recurse-delete icon indicating copy to clipboard operation
recurse-delete copied to clipboard

belongs_to :composite, :polymorphic => true, :dependent => destroy

Open pironim opened this issue 11 years ago • 3 comments

Maybe I'm a bit annoying but here is issue following association can't be simply deleted without instatiating or iterating through every record

class Content < ActiveRecord::Base belongs_to :composite, :polymorphic => true, :dependent => :destroy end

class UploadedFile < ActiveRecord::Base has_one :content, :as => :composite end

class ExternalLink < ActiveRecord::Base has_one :content, :as => :composite end

Main problem here - association class can't be detected using Model.reflect_on_all_associations. I don't have any good ideas how resolve this issue: some special strategy should be applyed in case of belongs_to :something, :polymorphic => true, :dependent => :destroy

pironim avatar Feb 12 '13 10:02 pironim

Is this different from issue #4?

jisaacks avatar Feb 12 '13 14:02 jisaacks

Yes it's different. There is opposite association where we have :polymorphic => true on the other side and association class always the same

pironim avatar Feb 12 '13 15:02 pironim

@pironim oh ok, I see the difference now.

association class can't be detected using Model.reflect_on_all_associations

I am not familiar with what data that will give you in this scenario but if the association can be detected (just not the class) then I am sure there should be some way or another to determine the class.

For example, when you say, Content.first.composite, I wonder what rails uses internally to determine the class.

I won't have time to look at this any time soon unfortunately.

jisaacks avatar Feb 12 '13 15:02 jisaacks