新手问题 升级到 Rails 5.1rc 后,belongs_to 好像成了必填项

QueXuQ · April 10, 2017 · Last by QueXuQ replied at April 10, 2017 · 1999 hits

原来的 Order model,有一个belongs_to :user,现在在创建 Order 时,会提示 user 不能为空。好奇怪,是因为新版本有什么更新的吗?去掉belongs_to :user就好了。

config/initializers/active_record_belongs_to_required_by_default.rb

# Require `belongs_to` associations by default. This is a new Rails 5.0 default, 
Rails.application.config.active_record.belongs_to_required_by_default = true

5.1 发布了?issues 上来看 rc 版 bug 很多呀

5 的时候就加了吧?除了一楼的还可以 belongs_to :user, optional: true

Reply to kikyous

😥 多谢,还一直不知道加了这个,目前新建一个项目才知道。

Reply to imwildcat

就是用 RC,目前用着好像没有特别明显的 bug。好像 ruby china 也是 rc1?

QueXuQ closed this topic. 10 Apr 19:58
You need to Sign in before reply, if you don't have an account, please Sign up first.