2

In my model class Project, I wish to create projects with a name. I validate the name like this:

  validates :name, :uniqueness => true

I would like the name for the projects to be unique, only in the scope of a User. Meaning, a user cannot have multiple projects with the same name, but the projects table may contain multiple projects with the same name, owned by different users.

Matt Taylor
  • 3,360
  • 1
  • 20
  • 34
user1121487
  • 2,662
  • 8
  • 42
  • 63

1 Answers1

10

see uniqueness with scope

validates :name, :presence => true, :uniqueness => {:scope => :user_id}
shweta
  • 8,019
  • 1
  • 40
  • 43