class User has_and_belongs_to_many :foos,uniq: trueend
因为当我调用user.foos时我只想要独特的foos,我添加了uniq选项.自升级到Rails 4以来,我开始收到以下警告:
DEPRECATION WARNING: The following options in your
User.has_and_belongs_to_many :foos declaration are deprecated: :uniq.
Please use a scope block instead. For example,the following:06001
should be rewritten as the following:
06002
我已经尝试了许多不同的组合,并通读源,但无法弄清楚如何编写唯一约束来删除警告?
解决方法class User has_and_belongs_to_many :foos,-> { uniq }end
根据documentation here
总结以上是内存溢出为你收集整理的ruby-on-rails – 在Rails 4中的has_and_belongs_to_many关系中使用uniq全部内容,希望文章能够帮你解决ruby-on-rails – 在Rails 4中的has_and_belongs_to_many关系中使用uniq所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)