SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot ricklach's Avatar
    Join Date
    Nov 2004
    Location
    Victoria BC
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validation of three fields question

    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

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Code:
    class App << ActiveRecord::Base
      validates_uniqueness_of :person_id, :app_type, :issue_id
    end

  3. #3
    SitePoint Zealot ricklach's Avatar
    Join Date
    Nov 2004
    Location
    Victoria BC
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think what I was looking for was more along the lines of
    Code:
    validates_uniqueness_of :person_id && :app_type && :issue_id
    . Unless the syntax is wrong, this fills the bill.

    Rick
    Ruby, Ruby when will you be mine

  4. #4
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  5. #5
    SitePoint Zealot ricklach's Avatar
    Join Date
    Nov 2004
    Location
    Victoria BC
    Posts
    116
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good point Douglas. Sometimes we forget the obvious.

    Rick
    Ruby, Ruby when will you be mine


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •