rails 5 关于修改数据之后配置了belongs_to :doctor如果doctor_id不填一直报错rollback transaction

来源:互联网 发布:项目经验怎么写 知乎 编辑:程序博客网 时间:2024/04/30 06:13

原文地址

2.3.0 :008 > TimeEntry.create(time:1.2, customer_id: 2)   (0.1ms)  begin transaction  Customer Load (0.1ms)  SELECT  "customers".* FROM "customers" WHERE "customers"."id" = ? LIMIT ?  [["id", 2], ["LIMIT", 1]]   (0.1ms)  rollback transaction => #<TimeEntry id: nil, time: 1.2, customer_id: 2, employee_id: nil, created_at: nil, updated_at: nil> 

解决办法

belongs_to :doctor, required: false
0 0
原创粉丝点击