views:

38

answers:

2

Are there any best practices / plugins for scoping users across different clients.

Currently we are validating the uniqueness of the email address on the assumption that these will be unique throughout the system

How would you recommend that we extend this approach to allow us to scope the uniqueness to a specific client-id...

Dom

+2  A: 
validates_uniqueness_of :email, :scope => :client_id

So the email will need to be valid for one client. But you will be able to have twice the same email for two different clients.

Damien MATHIEU
Thanks Damien, precisely what I was looking for and didn't even know it yet!
Gav
A: 

Assuming your User belongs_to a Client, you can do it in the user model.

validates_uniqueness_of :email, :scope => :client_id

Otherwise, I can't think of a good way to do it. I wouldn't be surprised if there's a plugin that does some scope + joins/includes magic.

EmFi
I know Authlogic supports scoping like this. Some of the other plugins probably do as well.
Daniel Kristensen