# \[ANN\] Squirrel plugin for better looking queries

**URL:** <https://www.ruby-forum.com/t/ann-squirrel-plugin-for-better-looking-queries/70516>\
**Category:** Rails\
**Created:** [September 29, 2006, 8:49pm UTC](https://www.ruby-forum.com/t/ann-squirrel-plugin-for-better-looking-queries/70516 "2006-09-29T20:49:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jyurek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c2a13f/32.png) [@jyurek](https://www.ruby-forum.com/u/jyurek)\
**Post date:** [September 29, 2006, 8:49pm UTC](https://www.ruby-forum.com/t/ann-squirrel-plugin-for-better-looking-queries/70516/1 "2006-09-29T20:49:46Z")

</div>

This is the first release of a new plugin for making very Rubyish  
queries. I never really liked AR’s find method syntax, and all the  
replacements I’ve seen didn’t make it any easier to join on multiple  
models at the same time, so I wrote Squirrel.

posts = Post.find do  
user.email =~ “%thoughtbot%”  
tags.name === %w( ruby rails )  
created\_on \<=\> [Time.now - 2.weeks, Time.now - 1.week]  
end

It overloads the base find method to take a block to build conditions,  
including any and all association joins. You reference them like you  
would in a normal block of Ruby.

You reference associations by whatever name you gave to it in the  
has\_many, belongs\_to, etc. You can then access all the columns and  
relationships on that model. It is rather specific, though, and will  
raise errors if you misspell your relationships or donâ??t pluralize  
right.

And you simply reference columns by their normal names and use any of  
==, ===, \<=\>, =~, \>=, \<=, \>, and \< on them pretty much like youâ??d expect  
to be able to (before you ask, yes, I cribbed the syntax from ez\_where,  
since it makes sense). It handles nil values in == with a quick trip to  
IS NULL and it handles negation of conditions through the unary -.

It’s not as full featured as I’d like it – yet, but IMHO it looks a lot  
better, and it’s still useful.

You can read further about it at  
[http://giantrobots.thoughtbot.com/2006/9/29/an-improvement-for-querying-in-rails](http://giantrobots.thoughtbot.com/2006/9/29/an-improvement-for-querying-in-rails)

Or you can install it via script/plugin install  
[http://svn.thoughtbot.com/plugins/squirrel](http://svn.thoughtbot.com/plugins/squirrel)

Jon Yurek  
[http://www.thoughtbot.com](http://www.thoughtbot.com)

---

<div class="post-metadata">

**Author:** ![jyurek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c2a13f/32.png) [@jyurek](https://www.ruby-forum.com/u/jyurek)\
**Post date:** [September 29, 2006, 11:45pm UTC](https://www.ruby-forum.com/t/ann-squirrel-plugin-for-better-looking-queries/70516/2 "2006-09-29T23:45:48Z")

</div>

Jon Yurek wrote:

> And you simply reference columns by their normal names and use any of
> 
> Or you can install it via script/plugin install  
> [http://svn.thoughtbot.com/plugins/squirrel](http://svn.thoughtbot.com/plugins/squirrel)
> 
> Jon Yurek  
> [http://www.thoughtbot.com](http://www.thoughtbot.com)

This looks really cool. I have a use for this in a project. I will let  
you know how it works out.

Matthew M.  
[blog.mattmargolis.net](http://blog.mattmargolis.net)

---

<div class="post-metadata">

**Author:** ![jyurek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c2a13f/32.png) [@jyurek](https://www.ruby-forum.com/u/jyurek)\
**Post date:** [September 30, 2006, 3:24am UTC](https://www.ruby-forum.com/t/ann-squirrel-plugin-for-better-looking-queries/70516/3 "2006-09-30T03:24:54Z")

</div>

This looks very nice. You might want to check out ez\_where though

---

<div class="post-metadata">

**Author:** ![jyurek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c2a13f/32.png) [@jyurek](https://www.ruby-forum.com/u/jyurek)\
**Post date:** [September 30, 2006, 4:02am UTC](https://www.ruby-forum.com/t/ann-squirrel-plugin-for-better-looking-queries/70516/4 "2006-09-30T04:02:55Z")

</div>

Looks like he has…

On 9/29/06, Daniel H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> This looks very nice. You might want to check out ez\_where though

---

<div class="post-metadata">

**Author:** ![jyurek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/c2a13f/32.png) [@jyurek](https://www.ruby-forum.com/u/jyurek)\
**Post date:** [September 30, 2006, 5:14pm UTC](https://www.ruby-forum.com/t/ann-squirrel-plugin-for-better-looking-queries/70516/5 "2006-09-30T17:14:30Z")

</div>

This is great, thank you. Going to check it out.
