Polymorphic Association with multiple associations on the same model?

Yep. That's totally possible You might need to specify the class name for header_image as it can't be inferred. Include :dependent => :destroy too, to ensure that the images are destroyed if the article is removed class Article :imageable, :class_name => 'Image', :dependent => :destroy has_many :images, :as => :imageable, :dependent => :destroy end then on the other end class Image true end.

Yep. That's totally possible. You might need to specify the class name for header_image, as it can't be inferred.

Include :dependent => :destroy too, to ensure that the images are destroyed if the article is removed class Article :imageable, :class_name => 'Image', :dependent => :destroy has_many :images, :as => :imageable, :dependent => :destroy end then on the other end... class Image true end.

That's great, thank you! – Jamie Rumbelow Jul 23 '09 at 22:07.

I tried this, but then header_image returns one of the images. Simply because the images table doesn't specify a different image use type (header_image vs. normal image). It simply says: imageable_type = Image for both uses.So if there's no information stored about the use type, ActiveRecord cannot differentiate.

You need single table inheritance – sharas Jul 17 '10 at 15:52.

I think that type in your question should be Post instead of Photo and, respectively, it would be better to use SecondaryPost as it assigned to Post model. Above answer is completly wrong. :foreign_type is availble in polymorphic model in belongs_to association to specify name of the column that contains type of associated model.

As you can see it uses base_class. Name to get type name.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions