I'm using DataMapper connected to an SQLite backend. I need to create a Unique index across my four belongs_to columns. Here is the table.
class Score
include DataMapper::Resource
property :id, Serial
property :score, Integer
belongs_to :pageant
belongs_to :candidate
belongs_to :category
belongs_to :judge
#What we want is a UNIQUE INDEX on the four properties!
end
Things I've done:
- A unique index on the four via something like :unique_index => :single_score. This works only if you have a property already included.
- validates_uniqueness_of, I think the scope only works for a 2-column unique index.
- My current solution, which is to just create a dummy field "dont_mind_me", just so I can put :unique_index => single_score in it and everything works. Is this something that's okay to do?
- Create an index using raw SQL, SQLite supports a unique index among the four fields.
Basically there are two parts of this question:
- Is my solution okay, or should I find another one? I'm at wit's end dealing with what seems to be something trivial, even with raw SQL
- How do I create an "after_create_table" hook in DataMapper? The hooks in the documentation only tell about post-CRUD data.