Hi hyn,
Have you declared title as a plain attribute (e.g., not using Typecast
Array) and are storing an array value? You are correct that find()
does not behave optimally if passed 'nil' or '[]' for the find value.
The behavior of Enumerable find values is changing slightly in 0.2.
Here are several things to be aware of:
find() with an Enumerable (e.g., Array) value in 0.1 operates as AND,
i.e. an intersection:
Post.find( title: ['t1', 't2'] ) will find all Posts where the title
array contains 't1' AND 't2'
However, in 0.2 this is changing to be 't1' OR 't2', in order to
support this broadly applicable functionality, i.e. title IN
[titles].
If you are depending on the 'AND' behavior, in 0.2 the solution is to
use the new Serialized module (evolution of Typecast) and to declare
the attribute explicitly as an Array. Although this preserves the
current behavior, it is a bit inconsistent, so I'm thinking of
removing it altogether. The solution would then be to simply chain the
find calls, Post.find(title: t1).find(title: t2) etc., which is what
it is doing internally anyway.
See
https://github.com/soveran/ohm/issues/27 for further details. I'd
appreciate any feedback if you are depending on support for this
behavior.
Note that each value of an Enumerable is individually indexed when the
object is stored. This has not changed. The above relates only to how
find processes its args.
I'll look to fix the find: nil and find: [] to properly return an
empty set.
If you can be on the edge with your project, you could try the 0.2
branch at
https://github.com/tribalvibes/ohm and let me know if you
encounter any problems with the above. (This branch still passes the
0.1 tests so there 'should' be minimal differences with other existing
features.)
Cheers,
.tv/