You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey folks, I'm making use of encrypted_id which overrides ActiveRecord's find method in order to handle decryption of an obfuscated id. I'm also using devise which makes use of orm_adapter to interact with ActiveRecord. At present devise is using the get method which is implemented using where/first vs a find and thus encrypted_id override doesn't work.
In order to consolidate on overriding find I have implemented a new version of the get method below.
# lib/orm_adapters/adapters/active_record.rb# @see OrmAdapter::Base#getdefget(id)# Ignore exceptions, be consistent on use of find for get and get!beginklass.find(wrap_key(id))rescuenilend# OR use dynamic finder which will return nil on not match, easier to subclass than a whereklass.find_by_id(wrap_key(id))# Previous implementation with where and first# klass.where(klass.primary_key => wrap_key(id)).firstend
Any thoughts on why this is a bad idea or maybe a better way that it could be done? If I opened a PR is this something that orm_adapter would be willing to accept?
Thanks for the ideas / feedback.
The text was updated successfully, but these errors were encountered:
Hey folks, I'm making use of encrypted_id which overrides ActiveRecord's
find
method in order to handle decryption of an obfuscated id. I'm also using devise which makes use of orm_adapter to interact with ActiveRecord. At present devise is using theget
method which is implemented using where/first vs a find and thus encrypted_id override doesn't work.In order to consolidate on overriding find I have implemented a new version of the
get
method below.Any thoughts on why this is a bad idea or maybe a better way that it could be done? If I opened a PR is this something that orm_adapter would be willing to accept?
Thanks for the ideas / feedback.
The text was updated successfully, but these errors were encountered: