Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pironim opened this issue Feb 12, 2013 · 3 comments
Open

Comments

@pironim
Copy link

pironim commented Feb 12, 2013

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

@jisaacks
Copy link
Owner

Is this different from issue #4?

@pironim
Copy link
Author

pironim commented Feb 12, 2013

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

@jisaacks
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants