Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does "imageable" mean in the rails docs explaining polymorphic associations?

So, I am trying to implement a polymorphic association and reviewing the Rails Docs, but am a but confused how they are using "imageable." Is "imageable" some sort of convention or should it really be tied to a table called "imageable"?

like image 785
notthehoff Avatar asked Feb 12 '23 22:02

notthehoff


1 Answers

imageable is an unwritten naming-convention in Rails polymorphic associations.

Another example is taggable - which refers to an object that can be tagged ie, that is taggable. Or for the imageable example, the object that has an attached image is imageable because it can accept an image.

In this case, you'd have columns on the belongs_to object (Picture) called imageable_id and imageable_type storing the id and model-class of the associated object. You don't need an imageable table... just the columns on the Picture model

like image 57
Taryn East Avatar answered Apr 08 '23 21:04

Taryn East