ruby on rails - Polymorphic Association with multiple associations on the same model -


I got a little confused about the polymorphic union. I need a paragraph model for a header image and multiple images, but I have to make an image model. To make the case more confusing, the image model is polymorphous (to allow other resources to keep multiple images).

I am using this link in my article model:

  class paragraph & lt; ActiveRecord :: Base has_one: header_image ,: as = & gt; : Image is qualified_mine: picture, as in: => : Imageable end  

Is this possible? Thank you.

Yes it is entirely possible.

You may have to specify the class name for header_image , because it can not be estimated. Include : Dependent = & gt; :

  class paragraph & lt; If deleted, delete  also to ensure that images have been deleted. ActiveRecord :: Base has_one: header_image ,: as = & gt; : Image worthy ,: class_name = & gt; 'Image' ,: Dependent = & gt; : Has_many deleted: images, as in => : Image, Dependent = & gt; : End of end  

then on the other end ...

  class image & lt; ActiveRecord :: Base is_to: imageable ,: polymorphic = & gt; True end  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -