Hi JP,
First, I'm sorry to have taken so long to replied to you. I did see
your message a couple weeks ago, but I was fighting day job fires at
the time and then I flaked. That was uncool of me.
Your question (about how to find records matching an array element) is
a good one, and certainly the answer isn't really documented in the
README right now. The README barely touches on Collection classes
because...well...I didn't feel like I was done with them yet. I was
kind of hoping people would look the other way for a little bit, and
then that little bit stretched out.
Regardless. I answered on Stack Overflow, but here's the answer
mirrored to the list for posterity:
* * * * * * * * * *
Candy doesn't implement a `find` method. This is on purpose: if an
object represents a collection, every access is implicitly _finding_
something in that collection. It's the same reason there is no `save`
method. If the mapping is truly transparent, verbs that mean "Do this
in the database" shouldn't be necessary.
So to do what you want, you could either just make a new Things object
with the scope passed on creation:
x_is_allowed = Things.new(allowed: 'X')
...or you could save a step and do it by class method:
x_is_allowed = Things.allowed('X')
...or you could start with the whole collection and limit it by attribute later:
things = Things.new
x_is_allowed = things.allowed('X')
So... Um. All of those will work. _But._ I have to warn you that
I'm really not happy with the general usability of Candy right now,
and of collections and array fields in particular. The biggest problem
is accessors: the `[]` method isn't working like you'd expect, so you
end up having to call `to_a` and `refresh` and other things that feel
sticky and unpleasant.
This needs to be fixed, and I will do so as soon as I finish the
driver rewrite (a related project called
[Crunch](http://github.com/sfeley/crunch)). In the short term, Candy
is probably best viewed as an experiment for the adventurous, and I
can't guarantee it'll save time until the interface is locked down a
bit better. I'm sorry about that.
--
Have Fun,
Steve Eley (sfe...@gmail.com)
ESCAPE POD - The Science Fiction Podcast Magazine
http://www.escapepod.org