我有一个验证has_many关联的唯一性的想法:如果我们根据关联记录的ids生成一个字符串,会怎么样?例如: has_many :problems #problems are unique and can be in multiple exams
def check
checksum = problems.map {|p
ArgumentError:未知键::唯一性。class League < ActiveRecord::Base has_one :user message: 'You can only create one team per league'end
一个联盟中有多支球队,但是球队必须有一个独特的user_id"user_id"
如果在创建记录时通过关联保存has_many:,如何确保关联具有唯一的对象。Unique由一组自定义属性定义。考虑: has_many :user_roles
has_many :roles, through: :user_rolesbecause it clears out the user roles which may have auxiliary data associated with them
但在这个问题上,我希望限制用户对一篇文章的一项评论投一票,这样评论就可以根据用户投票进行排名。因此,唯一性验证检查用户是否对文章的评论进行了投票。class User < ActiveRecord::Base end
has_many :comments
class Comment< ActiveRecord::B