# polymorphic association

**URL:** <https://discuss.rubyonrails.org/t/polymorphic-association/60721>\
**Category:** rubyonrails-talk\
**Created:** [September 4, 2011, 5:31pm UTC](https://discuss.rubyonrails.org/t/polymorphic-association/60721 "2011-09-04T17:31:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhishek\_shukla](https://avatars.discourse-cdn.com/v4/letter/a/7cd45c/32.png) [@Abhishek\_shukla](https://discuss.rubyonrails.org/u/Abhishek_shukla)\
**Post date:** [September 4, 2011, 5:31pm UTC](https://discuss.rubyonrails.org/t/polymorphic-association/60721/1 "2011-09-04T17:31:06Z")

</div>

Hello,

I have a scenario where I want to save a author image and book image to assets table…

I am using a polymorphic association.

And author\_name is inside the books table.

now when I save the image the imageable\_type says “Book” for both. And off-course it’s a correct behavior, but I am just trying to figure out is there any way where I can save author image and imageable\_type should have “AuthorImage” and it should call the same Book model

Solution: Other solution I am thinking to separate the Author from book and have it in another table.

Please it will be really helpful if someone can help me out.

Thanks abhis

---

<div class="post-metadata">

**Author:** ![11155](https://avatars.discourse-cdn.com/v4/letter/1/d26b3c/32.png) [@11155](https://discuss.rubyonrails.org/u/11155)\
**Post date:** [September 4, 2011, 8:15pm UTC](https://discuss.rubyonrails.org/t/polymorphic-association/60721/2 "2011-09-04T20:15:56Z")

</div>

I think you're adding only book\_images and no author\_images at all. But I'm nbot sure, because you're not providing your code

Try something like this: @asset.imageable = @author or AuthorImage.create attributes

I don't know if you made the right decision with using polymorphic associations. You need to provide more information what your associations are. For example: Author has\_many Images OR Author has\_one image And can the image belong to a book and an author as well?
