在开始将详细信息保存到数据库之前,我正在准备对象变量。Rails 4更新保存对象内容
我有3个对象,我需要保存order
,order_event
,message
我已经实例化对象order_event,并希望在我保存到数据库中更新订单参数
@order_event = OrderEvent.new(order_event_params)
@order_event.update_attributes(event_date: @event.event_date)
但Rails是试图将其保存到数据库并抛出以下错误
Mysql2::Error: Field 'order_id' doesn't have a default value: INSERT INTO `order_events` (`created_at`, `event_date`, `event_id`, `no_of_ppl`, `updated_at`) VALUES ('2015-04-17 10:20:11', '2015-01-22 00:00:00', 2, 1, '2015-04-17 10:20:11')
M Y型
--- !ruby/object:OrderEvent
attributes:
id:
order_id:
event_id: 2
no_of_ppl: 3
event_date:
cost:
total_cost:
status:
created_at:
updated_at:
我要在保存之前更新EVENT_DATE,成本TOTAL_COST等。
可能是你想使用'assign_attributes'?它不坚持对象。 – lx00st