laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org
2008-Mar-17 21:54 UTC
How would I construct this validation rule?
Hi, I have a column, "store_id" in my users table that could be blank, but otherwise it must be numeric. If someone does decide to enter a number, I want to ensure that number is unique relative to other store_id''s with non-null values. How, if possible, would I construct such a validation rule in my user model? Thanks, - Dave --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
laredotornado-8iDLEspWrrZBDgjK7y7TUQ@public.gmane.org wrote:> I have a column, "store_id" in my users table that could be blank, but > otherwise it must be numeric. If someone does decide to enter a > number, I want to ensure that number is unique relative to other > store_id''s with non-null values. How, if possible, would I construct > such a validation rule in my user model?validates_uniqueness_of :store_id, :allow_nil => true validates_numericality_of :store_id, :allow_nil => true And avoid use of #update_attribute (as this method avoids validations by default). -- 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?hl=en -~----------~----~----~----~------~----~------~--~---