Rails 问一个 Rails 5.0 版本问题

lengcb · September 19, 2017 · Last by jasl replied at September 19, 2017 · 1176 hits

最近项目里遇到一个问题,用的是 rails5.0 版本。有一个多对多的关系

has_many :assign_objectives,->{uniq}, through: :assign_key_results,  source: :objective

这应该是 rails3,rails4 版本的写法,我在网上查了一下,只查到 rails5.1 的写法

has_many : assign_objectives, through: :assign_key_results, :uniq => true, source: :objective

请问 rails5.0 的正确写法是什么?

发现好像不是版本的问题,我在 console 里老是报这个错误

ArgumentError: Unknown key: :uniq. Valid keys are: :class_name, :anonymous_class, :foreign_key, :validate, :autosave, :table_name, :before_add, :after_add, :before_remove, :after_remove, :extend, :primary_key, :dependent, :as, :through, :source, :source_type, :inverse_of, :counter_cache, :join_table, :foreign_type, :index_errors

错误提示告诉你 没有 uniq 这个参数

你希望应用层有唯一性验证的话,加唯一性验证器

lengcb closed this topic. 20 Sep 10:01
You need to Sign in before reply, if you don't have an account, please Sign up first.