# Validates\_associated on has\_many :through polymorphic exception

**URL:** <https://www.ruby-forum.com/t/validates-associated-on-has-many-through-polymorphic-exception/153891>\
**Category:** Rails\
**Created:** [November 22, 2008, 2:08pm UTC](https://www.ruby-forum.com/t/validates-associated-on-has-many-through-polymorphic-exception/153891 "2008-11-22T14:08:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gerhard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@gerhard](https://www.ruby-forum.com/u/gerhard)\
**Post date:** [November 22, 2008, 2:08pm UTC](https://www.ruby-forum.com/t/validates-associated-on-has-many-through-polymorphic-exception/153891/1 "2008-11-22T14:08:05Z")

</div>

I have a Company which has\_many AddressLinkings as AddressLinkable  
(polymorphic). The same Company has\_many Addresses through  
AddressLinkings. When creating a new Company and defining some  
Addresses for it, I want to validate the Addresses as well before  
saving anything to the database. The issue is that a  
ActiveRecord::RecordInvalid exception is being raised rather than the  
actual errors displayed. This baffles me. Why oh why?!?

Here is the code: [\_\_solution.rb · GitHub](http://gist.github.com/27683) .

Cheers guys!

---

<div class="post-metadata">

**Author:** ![gerhard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b5e925/32.png) [@gerhard](https://www.ruby-forum.com/u/gerhard)\
**Post date:** [November 22, 2008, 2:13pm UTC](https://www.ruby-forum.com/t/validates-associated-on-has-many-through-polymorphic-exception/153891/2 "2008-11-22T14:13:22Z")

</div>

Managed to figure this one out not a full half hour after making the  
post. Solution in the Gist.
