obfuscate_id icon indicating copy to clipboard operation
obfuscate_id copied to clipboard

Unable to find model with obfuscated ID via a has_many / through association

Open townhouse opened this issue 9 years ago • 7 comments

Somewhat related to #34.

Account model has obfuscated ID.

User.rb has_many :accounts, through: :memberships

AccountsController#show @account = current_user.accounts.find(params[:id])

Error Couldn't find Account with 'id'=0364209871 [WHERE "memberships"."user_id" = ?]

Workaround suggested in #34 works fine with direct find i.e. Account.find_by_id(params[:id]) but fails to find the account via association.

townhouse avatar Jul 20 '15 12:07 townhouse

+1

matoakley avatar Aug 18 '15 20:08 matoakley

+2

kevindewalt avatar Aug 26 '15 18:08 kevindewalt

I opened a Rails issue for that and asked if that is an error in ActiveRecord and if there is a better approach than overriding find: https://github.com/rails/rails/issues/21731

SebastianVomMeer avatar Sep 23 '15 08:09 SebastianVomMeer

+3

kierr avatar Jan 08 '16 08:01 kierr

I believe this implementation from friendly_id can be used as a basis https://github.com/norman/friendly_id/blob/master/lib/friendly_id/finders.rb https://github.com/norman/friendly_id/blob/master/lib/friendly_id/finder_methods.rb

freemanoid avatar Feb 08 '16 13:02 freemanoid

+4

wenweih avatar Dec 28 '16 07:12 wenweih

+5

rcerqueira-dv avatar May 24 '18 21:05 rcerqueira-dv