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
Let's say we have records that could be soft deleted (or any other default grouping property), and we want to search all records, but hide deleted by default:
With such setup, search by deleted: false works as expected ✅
Though, search by deleted: true doesn't work, because ActiveRecord adapter most of the time uses target.connection for queries, where target determined from relation.klass, here:
So, while response from Elastic has hits for such query (deleted: true), afterwards Chewy queries model directly with ids being found, which guarantee to return empty dataset every time (because of contradiction: we search for deleted, while querying only not deleted), ex:
User.where(id: ids_found_for_deleted_records_from_elastic_hits)# <= but User is scoped!
This looks like a bug for me, as we probably should query the same scope as we provide to index_scope method (everything what is indexed supposed to be searchable).
A little workaround is possible by extracting search results ids re-query them manually, like, but I would assume it should be a default behavior.
The text was updated successfully, but these errors were encountered:
Hi, thanks for the
gem
!Let's say we have records that could be soft deleted (or any other default grouping property), and we want to search all records, but hide deleted by default:
With such setup, search by
deleted: false
works as expected ✅Though, search by
deleted: true
doesn't work, becauseActiveRecord
adapter most of the time usestarget.connection
for queries, where target determined fromrelation.klass
, here:chewy/lib/chewy/type/adapter/orm.rb
Line 12 in ef0fab4
So, while response from Elastic has hits for such query (
deleted: true
), afterwardsChewy
queries model directly withids
being found, which guarantee to return empty dataset every time (because of contradiction: we search for deleted, while querying only not deleted), ex:This looks like a bug for me, as we probably should query the same scope as we provide to
index_scope
method (everything what is indexed supposed to be searchable).A little workaround is possible by extracting search results ids re-query them manually, like, but I would assume it should be a default behavior.
The text was updated successfully, but these errors were encountered: