Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Fix AR::RecordNotFound being raised with missing objects. #49

Merged
merged 2 commits into from
Oct 18, 2017

Conversation

savef
Copy link
Contributor

@savef savef commented Aug 25, 2015

The use of ActiveRecord's #find meant missing IDs raised AR::RecordNotFound. This might come up if an object was created and then deleted without its trigram data also being deleted. To avoid the exception this uses #where instead of #find which will ignore missing results.

Due to the method with which the records are sorted to match the trigram query, in these cases nils were cropping up in the results, so this uses #compact to just return the records.

The first test case ensures no exceptions for missing objects are raised. The second test case ensures the fuzzy find still works and that no nils are returned.


Excuse the whitespace removal, that was done automatically. Let me know if you want a rebased version without that.

The use of ActiveRecord's #find meant missing IDs raised AR::RecordNotFound. This might come up if an object was created and then deleted without its trigram data also being deleted. To avoid the exception this uses #where instead of #find which will ignore missing results.

Due to the method with which the records are sorted to match the trigram query, in these cases nils were cropping up in the results, so this uses #compact to just return the records.

The first test case ensures no exceptions are raised. The second test case ensures the fuzzy find still works and that no nils are returned.
@savef
Copy link
Contributor Author

savef commented Aug 25, 2015

This is failing with Rails 2 gems. I saw a comment from 2 years ago that you still wanted to support it, has anything changed?

@mezis mezis merged commit 026fd3d into mezis:master Oct 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants