# Polymorphic association vs HABTM

**URL:** <https://www.ruby-forum.com/t/polymorphic-association-vs-habtm/129434>\
**Category:** Rails\
**Created:** [February 18, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/polymorphic-association-vs-habtm/129434 "2008-02-18T16:18:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [February 18, 2008, 4:18pm UTC](https://www.ruby-forum.com/t/polymorphic-association-vs-habtm/129434/1 "2008-02-18T16:18:45Z")

</div>

Hello,  
Is there any advantage of using polymorphic associations instead of  
HABTM. Can anyone give me an example to explain.  
Thank you.

---

<div class="post-metadata">

**Author:** ![ankit2584](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/51bf81/32.png) [@ankit2584](https://www.ruby-forum.com/u/ankit2584)\
**Post date:** [February 18, 2008, 4:32pm UTC](https://www.ruby-forum.com/t/polymorphic-association-vs-habtm/129434/2 "2008-02-18T16:32:13Z")

</div>

has not much to do with each other

you would use polymorphic associations if you want to attach some kind  
of information and functionality to several other tables/models  
say for example you want to add image uploads to your app (which is some  
social thing for car fans as example).

users can upload images of themselves  
or  
they can upload images of their cars

the data stored and upload functionality is just the same for cars or  
users, so with polymorphic assocs you can just make both of them  
imagable

habtm relations just define, that two tables are related in a they, that  
each of them can be linked to many of the other kind

author has many books  
books have many authors
