Rails: validate uniqueness of two columns (together)

后端 未结 3 754
自闭症患者
自闭症患者 2020-12-02 06:58

I have a Release model with medium and country columns (among others). There should not be releases that share identical

3条回答
  •  天命终不由人
    2020-12-02 07:47

    You can pass a :scope parameter to your validator like this:

    validates_uniqueness_of :medium, scope: :country
    

    See the documentation for some more examples.

提交回复
热议问题