无法根据铁路7加密场获取ActivereCord模型

发布于 2025-02-08 07:59:41 字数 503 浏览 1 评论 0 原文

我有一个Rails 7应用程序,我决定在ActivereCord模型上加密字段。我采取了以下步骤:

  1. bin/rails db:加密:init
  2. rails凭据:编辑 - 环境开发,并在其中添加了密钥,
  3. 添加了加密:name

立即通过执行 somemodel.where(name:'blah')来查询模型时,即使记录在DB中,也不会返回任何记录。

但是,我可以:

  1. somemodel.all ,并验证记录是否存在并具有我要查询的值'blah',
  2. 如果我更改 gencrypts:name 加密:名称,确定性:true

我做错了什么,使查询在非确定性加密字段上失败?

I have a Rails 7 app and I decided to encrypt a field on an ActiveRecord model. I took the following steps:

  1. bin/rails db:encryption:init
  2. rails credentials:edit --environment development and added the keys there
  3. Added a encrypts :name to the model

Now when I query the model by doing SomeModel.where(name: 'blah'), it doesnt return any records even though the record is in the DB.

I can however:

  1. Do SomeModel.all and verify that the record exists and has the value 'blah' that I'm querying with
  2. Make the query work if I change encrypts: name to encrypts: name, deterministic: true

What am I doing wrong that's making the queries fail on non-deterministically encrypted fields?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

知你几分 2025-02-15 07:59:41

如果要查询加密属性,则需要制作加密确定性。

因此加密:名称,确定性:true

If you want to query the encrypted attribute, you need to make the encryption deterministic.

So encrypts :name, deterministic: true

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文