In Ruby on Rails Guide, is imageable a model? And does imageable have a database table?
How does imageable_id point to two different id attributes for Employee and Product?
In Ruby on Rails Guide, is imageable a model? And does imageable have a database table?
How does imageable_id point to two different id attributes for Employee and Product?
No, in the page that you linked, imageable represents a polymorphic association to either an Employee or Product. In order for the polymorphic association to work, rails will need to determine the 'type' of object (i.e. either an Employee or a Product) by looking at the 'imageable_type' entry in the db and then the id of the respective object (imageable_id).
For example, an entry within the db of imageable_type => 'Employee' and and imageable_id => '4'. ActiveRecord would figure out that the association is to id 4 in the employees table.
Imageable is not a model. It is a placeholder for some model (in this case either Employee or Product).
The way imageable_id can point to different kinds of ids is that Picture also has an imageable_type attribute. For a given instance of Picture, it knows what kind of id imageable_id represents by looking at it's imageable_type.