Single Table Inheritance and validation

Hello guys,

I’ve got a User table, which is inherited by AdminUser and Supplier. In my User model, I have a validates_uniqueness_of :email however I am still able to store records with duplicate email addresses.

Does anyone have any suggestions why this might be occurring?



Maybe try putting the validation on the AdminUser and Supplier models directly. Let me know if that works. I seem to recall having to do that in my app.

My validation rule was in the User model and my Admin/Supplier models extend User. In the end, I found a method someone had written who was having a similar problem to me.

This seems to have fixed the problem.



Hi Alastair,

Did you ever solve this problem? I have this EXACT issue myself. I ASSumed that the validates_unique was working because I’ve seen it working but didn’t think to check for trying to have the same email for a different subtype. I immediately put a unique index on the email column and am looking for the right rails validation to set for this to work properly at the application layer. I don’t care what folks say about being able to through out FK constraints, this little episode is enough for me now to make sure they are everywhere I need to ensure integrity.