validates_uniqueness_of with HABTM relationship
- by jeffshantz
I've got a HABTM relationship between two models: Publication and Author. I want to ensure that one cannot create a publication with the same title, year, and author list. However, if I try something like this:
class Publication < ActiveRecord::Base
validates_uniqueness_of :title, :scope => [:year, :authors]
end
This obviously won't work since there is no authors column. Can this be done with validates_uniqueness_of, or do I need a custom validator? Thank you.