Fix the issue with a single object vs array being returned #725
Conversation
Passes locally. 807 tests, 807 passed, 0 failures, 0 errors, 0 skips, 1827 assertions |
@@ -136,7 +136,7 @@ def __get_results_with_load(hits) | |||
"based on _type '#{type}'.", e.backtrace | |||
end | |||
|
|||
records[type] = __find_records_by_ids klass, items.map { |h| h['_id'] } | |||
records[type] = [*(__find_records_by_ids klass, items.map { |h| h['_id'] })] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Array(__find_records_by_ids klass, items.map { |h| h['_id'] }))
instead?
That might happen, I guess. Would it be possible to add a unit/integration test demonstrating the issue? |
Oh awesome, didn't know the Array constructor worked like that. test/integration/persisted_model_test.rb:47 is the test that should break if you undo the fix. |
@SixiS Yeah, the BTW, I have removed the |
Great, thanks! The active record test was not failing, I was having the issue using the persistence model. If you do not use load: true with the persistence model, methods on the returned objects return nil. If you do use load :true before the array fix you got the detect problem. Tho maybe the fact that the methods return nil and not what you expect is another problem on its own. I think it is because the objects returned are not real instances of their models but a sort of casted Item model. Thanks for taking the time to close this issue! |
So, you're using |
Exactly 😄 We are using Tire.search for more complicated searches on the persisted indexes (multiple index and multiple search). Which is where we were running into the 'no method detect' problem because we wanted to use load: true. |
If you use load: true when the search would return a single object it raises the error
NoMethodError:
undefined method `detect' for #<--elastic search persistance model-->
This has been fixed before but it must have been lost when the code was refactored.
See #353
Original issue:
http://stackoverflow.com/questions/10592005/tire-gem-undefined-method-detect