One of the many cool things of Ruby on Rails are magic ﬁnders, or Dynamic attribute-based ﬁnders as the documentation calls them. Thanks to them we can write:
User.find(:first, ['login = ? and status = ?', some_login, 1])
The ﬁrst form is shorter and easier for human to parse.
Unfortunately, we can only combine attributes using
and operator, but the possibility to use
not operators would also be nice. And, as always when using Ruby on Rails, when we ﬁnd that library is lacking some feature, we can easily add it. Let’s see how to do it.