MongoID 为任何异常抛出错误数量的参数红宝石 3​​.0.0 + Rails 6.1.3.1

问题描述

我的堆栈是

红宝石 3​​.0.0 导轨 6.1.3.1 Mongoid 7.1.2

Mongo 在应该引发其他人时总是抛出相同的异常:

ArgumentError (wrong number of arguments (given 3,expected 1..2))

例如:

我对字段进行了唯一性验证:

irb(main):010:0> Model.create!(field: 'sape')
=> #<Model _id: 606207343dcde26a1595eb48,created_at: 2021-03-29 16:58:28.006091 UTC,updated_at: 2021-03-29 16:58:28.006091 UTC,field: "sape">

irb(main):011:0> Model.create!(field: 'sape')
Traceback (most recent call last):
        1: from (irb):11:in `<main>'
ArgumentError (wrong number of arguments (given 3,expected 1..2))

find_by 也一样: 如果响应找到一个,它会检索它:

irb(main):012:0> Model.find_by(field: 'sape')
=> #<Model _id: 606207343dcde26a1595eb48,created_at: 2021-03-29 16:58:28.006 UTC,updated_at: 2021-03-29 16:58:28.006 UTC,field: "sape">

但是如果它不存在:

irb(main):001:0> Model.find_by(field: 'sape')
Traceback (most recent call last):
        1: from (irb):1:in `<main>'
ArgumentError (wrong number of arguments (given 2,expected 0..1))

这是我的模型:

class Model
  include ActiveModel::Validations
  include Mongoid::Document
  include Mongoid::Timestamps::Created
  include Mongoid::Timestamps::Updated

  field :field,type: String,default: nil

  index({ field: 1 },{ unique: true })
end

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)