我正在尝试让Clearance使用 AWS Dynamo 作为后端存储。我遇到的问题是我无法获得不进行电子邮件唯一性验证的许可,因为它无法通过 SQL 查询进行标准的 ActiveRecord 唯一性验证,所以它不能这样做。
根据代码中的注释,我应该能够让我的User
对象返回email_optional?
true
,这应该会禁用电子邮件的唯一性验证。所以我有:
class User < ApplicationRecord
include Dynamoid::Document
include Clearance::User
field :name
field :email
def email_optional?
puts 'yes, email is optional'
true
end
end
但是,当我尝试创建用户时出现错误,更重要的puts
是,没有执行:
$ rails c
Running via Spring preloader in process 18665
Loading development environment (Rails 5.1.3)
irb(main):001:0> u = User.new(name: 'ijd', email: 'ian@fu.bar', password: 'test')
ActiveRecord::StatementInvalid: Could not find table 'editor_development_users'
from (irb):1
更新:@spickermann 的回复提醒我,我应该注意到我也尝试过不进行子类化ActiveRecord::Base
(通过ApplicationRecord
)。它给出了一个不同的错误:
class User
include Dynamoid::Document
....
irb(main):002:0> reload!
Reloading...
=> true
irb(main):003:0> u = User.new(name: 'ijd', email: 'ian@fu.bar', password: 'test')
ArgumentError: Unknown validator: 'UniquenessValidator'
from app/models/user.rb:4:in `include'
from app/models/user.rb:4:in `<class:User>'
from app/models/user.rb:2:in `<top (required)>'
from (irb):3