Rails 7: Active Record Encryption: Not supported
john-999 opened this issue · 3 comments
Rails 7 Active Record Encryption (https://guides.rubyonrails.org/active_record_encryption.html) is not supported:
gem 'activerecord', '7.0.2.3'
gem 'globalize', '6.1.0'
Thanks; in what way would you expect this library to support it?
Hi @parndt !
Consider the following scenario:
# models/technique.rb
class Technique < ApplicationRecord
translates :name
encrypts :name, deterministic: true, ignore_case: true # <<--- from: Rails 7's Active Record Encryption
end
irb(main):001:0> technique = Technique.new()
irb(main):002:0> technique.attributes = { locale: 'fr', name: "Une nouvelle technique" }
irb(main):003:0> technique.save
Expected outcome: Globalize should let Rails write the following to the DB:
technique_translations.name
should contain the encrypted value (downcased by Rails Active Record Encryption) of the attributetechnique.name
technique_translations.original_name
should contain the encrypted value (with original casing preserved by Rails Active Record Encryption) of the attributetechnique.name
Current outcome:
irb(main):001:0> technique = Technique.new()
[...]/gems/activerecord-7.0.3/lib/active_record/encryption/encryptable_record.rb:97:in `preserve_original_encrypted': To use :ignore_case for 'name' you must create an additional column named 'original_name' (ActiveRecord::Encryption::Errors::Configuration)
However, the additional column named original_name
is definitely present in the table technique_translations
.
Rails is certainly looking for this column in the table techniques
where it is of course not. If I understand this situation correctly, then this would be an argument for integrating Globalize into the Rails core.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.