我尝试插入记录,但 Active Record 做了同样的魔法,我不明白!?!?!?我的测试代码:
UserToken.where(:user_id=>2).first_or_initialize.tap do |user|
user.token = 'token',
user.type_id = 0,
user.user_id = 2
user.save!
end
结果:
UserToken Load (56.9ms) SELECT `user_tokens`.* FROM `user_tokens` WHERE `user_tokens`.`user_id` = 2 LIMIT 1
(56.4ms) BEGIN
(56.4ms) UPDATE `user_tokens` SET `type_id` = 0, `token` = '---\n- token\n- 0\n- 2\n', `updated_at` = '2013-06-27 20:19:22' WHERE `user_tokens`.`id` = 19
(56.3ms) COMMIT
=> #<UserToken id: 19, user_id: 2, token: ["token", 0, 2], type_id: 0, created_at: "2013-06-27 20:14:11", updated_at: "2013-06-27 20:19:22">
为什么更新 token token
= '---\n- token\n- 0\n- 2\n', token: ["token", 0, 2] 我只是尝试记录'token'而不是数组?!?!? !?