我擁有數組類型Time
。當我嘗試以下面的方式插入數據IAM得到錯誤。無法將Time對象保存到列時間數組中,在Ruby on Rails中
2.2.2 :001 > p = PunchInOut.new
=> #<PunchInOut id: nil, employee_id: nil, check_in: [], check_out: [], date: nil, created_at: nil, updated_at: nil, shift_id: nil, shift_name: nil>
2.2.2 :002 > p.check_in << Time.now
=> [2015-09-18 19:25:11 +0530]
2.2.2 :003 > p.save
(0.3ms) BEGIN
SQL (1.2ms) INSERT INTO `punch_in_outs` (`check_in`, `check_out`, `created_at`, `updated_at`) VALUES ('---\n- 2015-09-18 19:25:11.695612520 +05:30\n', '--- []\n', '2015-09-18 13:55:19', '2015-09-18 13:55:19')
Mysql2::Error: Incorrect time value: '---
- 2015-09-18 19:25:11.695612520 +05:30
' for column 'check_in' at row 1: INSERT INTO `punch_in_outs` (`check_in`, `check_out`, `created_at`, `updated_at`) VALUES ('---\n- 2015-09-18 19:25:11.695612520 +05:30\n', '--- []\n', '2015-09-18 13:55:19', '2015-09-18 13:55:19')
(0.1ms) ROLLBACK
ActiveRecord::StatementInvalid: Mysql2::Error: Incorrect time value: '---
- 2015-09-18 19:25:11.695612520 +05:30
' for column 'check_in' at row 1: INSERT INTO `punch_in_outs` (`check_in`, `check_out`, `created_at`, `updated_at`) VALUES ('---\n- 2015-09-18 19:25:11.695612520 +05:30\n', '--- []\n', '2015-09-18 13:55:19', '2015-09-18 13:55:19')
iam using mysql database。並且還將模式中的這些列序列化。仍然iam得到錯誤
這是代碼亞姆在模型中。
class PunchInOut < ActiveRecord::Base
serialize :check_in, Array
serialize :check_out, Array
end
請幫幫我。