In a table I want to validate as unique three fields person_id, app_type and issue_id so that no duplicates appear in the table. Is there a special syntax for this type of validation?
Rick
| SitePoint Sponsor |

In a table I want to validate as unique three fields person_id, app_type and issue_id so that no duplicates appear in the table. Is there a special syntax for this type of validation?
Rick
Ruby, Ruby when will you be mine
Code:class App << ActiveRecord::Base validates_uniqueness_of :person_id, :app_type, :issue_id end

I think what I was looking for was more along the lines of. Unless the syntax is wrong, this fills the bill.Code:validates_uniqueness_of :person_id && :app_type && :issue_id
Rick
Ruby, Ruby when will you be mine





The easiest way would be to add a composite "UNIQUE" index to the database, I'm not sure how to do it with the built in validators.
Douglas
Hello World

Good point Douglas. Sometimes we forget the obvious.
Rick
Ruby, Ruby when will you be mine
Bookmarks