Hello all, I was wondering if someone could give me a brief explanation of how :scope works. I believe I''ve seen it used with the validation helpers in the past. - Jim
If you have a look at the docs for ''validates_uniqueness_of'', you''ll see this example: class Person < ActiveRecord::Base validates_uniqueness_of :user_name, :scope => "account_id" end Basically, what that means is that the vaildation of user_name will not just be checked against _all_ other usernames, it will instead be checked against only those usernames where the account_id is the same as the model under validation. HTH, Dan
Dan Sketcher wrote:>If you have a look at the docs for ''validates_uniqueness_of'', you''ll >see this example: > > class Person < ActiveRecord::Base > validates_uniqueness_of :user_name, :scope => "account_id" > end > >Basically, what that means is that the vaildation of user_name will >not just be checked against _all_ other usernames, it will instead be >checked against only those usernames where the account_id is the same >as the model under validation. > >HTH, >Dan >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >Wow, thanks for that. I had written a custom (ugly) validation to do the same thing but that is much nicer. Cheers, Sam
Reasonably Related Threads
- When adding a record in console, a parameter comes in as null even when I set it
- How to write a test for validates_uniqueness_of
- validates_uniqueness_of does not pass unit test
- error_message_on broken?
- validates_uniqueness_of where scope euqals created_by "magic" field