recurse-delete
recurse-delete copied to clipboard
belongs_to :composite, :polymorphic => true, :dependent => destroy
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
Is this different from issue #4?
Yes it's different. There is opposite association where we have :polymorphic => true on the other side and association class always the same
@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.