activemodel(和 MS SQL)的 PaperTrail gem 问题

PaperTrail gem issue with activemodel (and MS SQL)

提问人:Mykolas 提问时间:7/25/2023 更新时间:7/25/2023 访问量:38

问:

我正在尝试设置 PaperTrail gem 以使用 Rails 7 (Ruby 3.2.2) 和 MS SQL 数据库。当使用JSON作为PaperTrail的序列化器时,序列化/反序列化日期似乎有问题:

在application.rb中,我有:

PaperTrail.serializer = PaperTrail::Serializers::JSON

Gemfile 中的 PaperTrail 版本:

gem 'paper_trail', '~> 14.0'

我得到的错误:

irb(main):012:0> Project.last.versions.last.changeset
  Project Load (5.7ms)  EXEC sp_executesql N'SELECT [projects].* FROM [projects] ORDER BY [projects].[id] DESC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY', N'@0 int', @0 = 1  [["LIMIT", nil]]
  PaperTrail::Version Load (4.4ms)  EXEC sp_executesql N'SELECT [versions].* FROM [versions] WHERE [versions].[item_id] = @0 AND [versions].[item_type] = @1 ORDER BY [versions].[created_at] DESC, [versions].[id] DESC OFFSET 0 ROWS FETCH NEXT @2 ROWS ONLY', N'@0 bigint, @1 nvarchar(4000), @2 int', @0 = 1, @1 = N'Project', @2 = 1  [["item_id", nil], ["item_type", nil], ["LIMIT", nil]]
  Project Load (3.4ms)  EXEC sp_executesql N'SELECT [projects].* FROM [projects] WHERE [projects].[id] = @0 ORDER BY [projects].[id] ASC OFFSET 0 ROWS FETCH NEXT @1 ROWS ONLY', N'@0 bigint, @1 int', @0 = 1, @1 = 1  [["id", nil], ["LIMIT", nil]]
/usr/local/bundle/gems/activemodel-7.0.4.3/lib/active_model/type/date_time.rb:40:in `value_from_multiparameter_assignment': Provided hash {"value"=>"07-25-2023 07:28:02.245688", "type"=>{"precision"=>6, "scale"=>nil, "limit"=>nil}} doesn't contain necessary keys: [1, 2, 3] (ArgumentError)

            raise ArgumentError, "Provided hash #{values_hash} doesn't contain necessary keys: #{missing_parameters}"
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
irb(main):013:0>

任何想法可能出了什么问题?

Ruby-on-Rails SQL-Server 活动模型序列化程序 ActiveModel Paper-Trail-gem

评论


答: 暂无答案