Closed pramodshinde closed 3 years ago
Hey @pramodshinde, Lockbox attributes are excluded from as_json
by default. You can use:
u.as_json(methods: [:first_name])
For u.first_name
returning nil
, make sure you've followed the Lockbox backfill instructions.
Hey @ankane thanks for response,
as_json is working when it is given in methods list
u.as_json(methods: [:first_name])
I am not using Lockbox backfill i.e. Lockbox.migrate(User)
explicitly but something similar,
like
updated_records = []
User.find_each do |recond|
updated_records << record.send("first_name=", record.send("first_name"))
end
then with active record import
User.import(updated_records,
validate: false,
timestamps: false
)
This is because we need to skip all callbacks and to achieve bit faster backfill. Above is successfully migrating/backfilling data and adding ciphertext columns.
Not sure why u.first_name
in returning nil
as we are not doing anything special.
I'm guessing it's something with the custom backfill code. If u.first_name_ciphertext
is nil
, u.first_name
will return nil
.
thanks found issue, In our code base first_name method was overriden , which was causing u.first_name
to return nil
Is there any way where I can override encrypted field like
def first_name
super
self.first_name.strip_special_characters
end
Inside above method I am getting first_name
as nil
P.S. Closing this for now if you have any advice on this that would be great help.
You can use Module#prepend
in Ruby to override just about any method, but it's not officially supported by the library. See this comment for code.
I have implemented bling index in combination with Lockbox like following
Added index and column like in migration
User Model
I backfilled data and following is working fine before dropping origin column :first_name
Though Not returning first_name in JSON
After dropping origin column :first_name, u.first_name is nil
Ruby 2.6.6 rails', '~> 5.2.4' lockbox (0.6.5) blind_index (2.2.0)
Let me know if I am missing something here