# Single-table inheritance and validation problem

**URL:** <https://www.ruby-forum.com/t/single-table-inheritance-and-validation-problem/163330>\
**Category:** Rails\
**Created:** [March 19, 2009, 10:38am UTC](https://www.ruby-forum.com/t/single-table-inheritance-and-validation-problem/163330 "2009-03-19T10:38:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefan\_Frede](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5e9695/32.png) [@Stefan\_Frede](https://www.ruby-forum.com/u/Stefan_Frede)\
**Post date:** [March 19, 2009, 10:38am UTC](https://www.ruby-forum.com/t/single-table-inheritance-and-validation-problem/163330/1 "2009-03-19T10:38:34Z")

</div>

Hi!

I’ve got a subscription form in which someone can decide to give a  
gift to someone else. So you have to enter subscriber and recipient  
data in one form.

For my user model I use single-table inheritance. It works fine but  
I’ve got a bug in the validation which I’m not able to solve.

For both users, subscriber and recipient, you have to enter an email  
address. It is important that the email address is unique so you have  
to enter two different email addresses.

In my parent user model I validate the email input with  
validates\_uniqueness\_of :email. This checks if there is an existing  
email address in the database already but not if the email input of  
both users are the same.

My bug is due to the save order and the validation of uniqueness that  
then the second user will not be saved but the system also do not  
throw an error.

I hope this is somehow understandable. Here some code that hopefully  
shows the problem:  
[http://pastie.org/pastes/419606](http://pastie.org/pastes/419606)

So my question is how can I compare the email input to throw an error  
if they are the same.

Thanks in advance.

Regards,  
Stefan
