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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.