人
在控制器中发出以下代码块时,生成的SQL不包含模型的一列/ attr:
dev_total = DeviceTotal.where(time_stamp: @time_stamp).first_or_create {|dt|
dt.dev_utc = @utc,
dt.value = @grand_total,
dt.production = @net_weight,
dt.device_id = @device.id,
dt.var = @device.variable.symbol
}
结果SQL:
INSERT INTO "device_totals" ("created_at", "device_id", "production", "time_stamp",
"updated_at", "value", "var") VALUES ($1, $2, $3, $4, $5, $6, $7)
RETURNING "id" [["created_at", Wed, 09 Oct 2013 22:54:04 UTC +00:00],
["device_id", 1], ["production", 80.38], ["time_stamp", Wed, 09 Oct 2013 22:53:59
UTC +00:00], ["updated_at", Wed, 09 Oct 2013 22:54:04 UTC +00:00], ["value",
847.25], ["var", "FRL"]]
可以看出,“dev_utc”列未包含在INSERT命令中。所有其他属性都保存到DB。这是一个BigInt类型列。
其他一切都很好。 检查我的代码几十次没有运气。
任何线索?