Quick tips: ActiveRecord Find with array of IDs
Last week I discovered something that I always think that did not work. I was looking for a user on rails console, and because a mistake, instead of copy and paste a uniq ID, I typed
User.find( and pasted an array of IDs, closed the parenthesis and press . I expected that rails throw an exception because find should receive an ID to return one record only. For my surprise, the method works fine and returns a array of users.
So, searching more about this, I found that in the RubyOnRails docs it is explained(link) and is a expected behaviour. Another interested thing is that the resulted array bring records with same order of IDs array passed, so, if I type
User.find([3,5,4,6]) it will return user with id 3 in first place of array, then user #5, than user #4 and last user #6.