跳至内容 跳至搜索

自动扩展加密参数以支持查询加密和未加密数据

Active Record Encryption 支持使用确定性属性查询数据库。例如

Contact.find_by(email_address: "[email protected]")

值“[email protected]” 将被自动加密以执行查询。但数据加密时存在问题。这将不起作用。在此期间,您需要这些查询

Contact.find_by(email_address: [ "[email protected]", "<encrypted [email protected]>" ])

此补丁 ActiveRecord 以自动支持此功能。它同时解决了

如果 ‘config.active_record.encryption.extend_queries` 为 `true`,则包含此模块。

命名空间
方法

类公共方法

install_support()

# File activerecord/lib/active_record/encryption/extended_deterministic_queries.rb, line 24
def self.install_support
  # ActiveRecord::Base relies on ActiveRecord::Relation (ActiveRecord::QueryMethods) but it does
  # some prepared statements caching. That's why we need to intercept +ActiveRecord::Base+ as soon
  # as it's invoked (so that the proper prepared statement is cached).
  ActiveRecord::Relation.prepend(RelationQueries)
  ActiveRecord::Base.include(CoreQueries)
  ActiveRecord::Encryption::EncryptedAttributeType.prepend(ExtendedEncryptableType)
end