validates_uniqueness_of with HABTM relationship
        Posted  
        
            by jeffshantz
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by jeffshantz
        
        
        
        Published on 2010-03-15T00:35:59Z
        Indexed on 
            2010/03/15
            0:39 UTC
        
        
        Read the original article
        Hit count: 380
        
ruby-on-rails
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.
© Stack Overflow or respective owner