验证多列的唯一性 [英] Validate uniqueness of multiple columns
本文介绍了验证多列的唯一性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种验证实际记录是唯一的而不仅仅是一列的方法?例如,友谊模型/表格不应具有多个相同的记录,例如:
Is there a rails-way way to validate that an actual record is unique and not just a column? For example, a friendship model / table should not be able to have multiple identical records like:
user_id: 10 | friend_id: 20
user_id: 10 | friend_id: 20
推荐答案
您可以将 validates_uniqueness_of
调用如下。
validates_uniqueness_of :user_id, :scope => :friend_id
这篇关于验证多列的唯一性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文