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? Thanks, Alastair ------ Alastair Moore Standards compliant web development with Ruby On Rails, PHP and ASP www.kozmo.co.uk 07738 399038 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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. On 8/29/06, Alastair Moore <alastair-mb+lb5rSoAr10XsdtD+oqA@public.gmane.org> wrote:> > 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? > > Thanks, > > Alastair > > ------ > Alastair Moore > Standards compliant web development with Ruby On Rails, PHP and ASP > www.kozmo.co.uk > 07738 399038 > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Alastair Moore wrote:> 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.Where did you define your validation rule? (It should be inside the parent model User if you want it to affect all children.) Also, do your AdminUser and Supplier models extend User or ActiveRecord? They''ll need to extend User if the rule is to be applied to them. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Brian Hogan wrote:> 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.You shouldn''t have to. And doing so would indicate you''re not inheriting from the User model. Example, bad: class UserAdmin < ActiveRecord::Base end Example, good: class UserAdmin < User end The Rails generator does not do this automatically for you, so you must. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 29 Aug 2006, at 18:57, Daniel Waite wrote:> > Alastair Moore wrote: >> 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. > > Where did you define your validation rule? (It should be inside the > parent model User if you want it to affect all children.) > > Also, do your AdminUser and Supplier models extend User or > ActiveRecord? > They''ll need to extend User if the rule is to be applied to them.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. http://work.alexyoung.org/archives/99/single-table-inheritance-and- validates_as_unique This seems to have fixed the problem. Cheers! Alastair ------ Alastair Moore Standards compliant web development with Ruby On Rails, PHP and ASP www.kozmo.co.uk 07738 399038 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Alastair Moore wrote:> http://work.alexyoung.org/archives/99/single-table-inheritance-and- > validates_as_uniqueThat''s pretty cool. Nice find and thanks for sharing. =) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
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. Best, -Michael http://javathehutt.blogspot.com On Aug 29, 2006, at 9:50 AM, Alastair Moore wrote:> 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? > > Thanks, > > Alastair > > ------ > Alastair Moore > Standards compliant web development with Ruby On Rails, PHP and ASP > www.kozmo.co.uk > 07738 399038 > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---