# Improved find syntax in rails

**URL:** <https://www.ruby-forum.com/t/improved-find-syntax-in-rails/144702>\
**Category:** Rails\
**Created:** [August 1, 2008, 10:48am UTC](https://www.ruby-forum.com/t/improved-find-syntax-in-rails/144702 "2008-08-01T10:48:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xgamerx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/d2c977/32.png) [@xgamerx](https://www.ruby-forum.com/u/xgamerx)\
**Post date:** [August 1, 2008, 10:48am UTC](https://www.ruby-forum.com/t/improved-find-syntax-in-rails/144702/1 "2008-08-01T10:48:50Z")

</div>

Hey guys, I was told to move discussion to the mailing list so that is  
what I am doing. I recently started working with merb and datamapper and  
I am really fond of moving the super simple conditions syntax over to  
rails.

Here is the (closed) ticket:

[http://rails.lighthouseapp.com/projects/8994/tickets/335-improve-conditions-hash-to-support-more-complex-queries](http://rails.lighthouseapp.com/projects/8994/tickets/335-improve-conditions-hash-to-support-more-complex-queries)

Here are some examples of the syntax in action:

Person.find(:all, :conditions =\> { :age.gt =\> 30, :name.like =\> “%name%”  
})  
Person.all(:conditions =\> { :name =\> “Bob”, :age.gt =\> 25 }) #  
returns all records that match ‘all’ conditions  
Person.all(:conditions =\> { :name.eql =\> “Bob”, :age.gt =\> 25 })  
Person.all(:conditions =\> { :name.like =\> “%ob%”, :age.lte =\> 55 })  
Person.all(:conditions =\> { :name.like =\> “%ob%”, :age.in =\> [55, 56,  
57] })  
Person.all(:conditions =\> { :name.like =\> “%ob%”, :age.not =\> [55, 56,  
57] })

While, I have built a plugin that works with Rails 2.1 and below, this  
functionality is so simple and so elegant, I am interested in trying to  
get this into rails core.

Also, I find that this area is constantly changing which requires  
constant maintenance of the plugin. I believe this simple fix would be  
better suited to being in rails and it would benefit a lot of people  
when they first start building queries.

The plugin is here: [http://github.com/xgamerx/conditions\_fu/tree/master](http://github.com/xgamerx/conditions_fu/tree/master)

If I was willing to create the patch and the associated tests, would  
this be able to be accepted into rails? Any thoughts or suggestions on  
the matter?

---

<div class="post-metadata">

**Author:** ![xgamerx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/d2c977/32.png) [@xgamerx](https://www.ruby-forum.com/u/xgamerx)\
**Post date:** [August 1, 2008, 10:53am UTC](https://www.ruby-forum.com/t/improved-find-syntax-in-rails/144702/2 "2008-08-01T10:53:01Z")

</div>

I forgot to mention that in the ticket, it is mentioned this may be  
redundant effort because of the plugin here:  
[http://github.com/nkallen/arel/tree](http://github.com/nkallen/arel/tree)

Now I could be wrong but while this plugin seems useful as does this:

> <https://github.com/zdennis/ar-extensions/tree/master/ar-extensions>
>
> //github.com/zdennis/ar-extensions/tree/master/ar-extensions

Both seem a bit too heavy handed to be part of the actual rails  
codebase. I am not convinced all that should be within the rails core. I  
am convinced that the simple ability to use conditions hashes while  
being given the added flexibility of greater-than, less-than, like, not,  
etc should be.

---

<div class="post-metadata">

**Author:** ![xgamerx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/d2c977/32.png) [@xgamerx](https://www.ruby-forum.com/u/xgamerx)\
**Post date:** [August 1, 2008, 11:12am UTC](https://www.ruby-forum.com/t/improved-find-syntax-in-rails/144702/3 "2008-08-01T11:12:58Z")

</div>

On Aug 1, 9:48 am, Nathan E. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hey guys, I was told to move discussion to the mailing list so that is  
> what I am doing. I recently started working with merb and datamapper and  
> I am really fond of moving the super simple conditions syntax over to  
> rails.

Pratik probably meant the rails-core list (which is explicitly about  
development of rails itself) as opposed to this general more usage  
oriented list. Not that there’s anything wrong with posting here, but  
the readership will be different.

Fred

---

<div class="post-metadata">

**Author:** ![xgamerx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/d2c977/32.png) [@xgamerx](https://www.ruby-forum.com/u/xgamerx)\
**Post date:** [August 1, 2008, 11:17am UTC](https://www.ruby-forum.com/t/improved-find-syntax-in-rails/144702/4 "2008-08-01T11:17:22Z")

</div>

That’s a fair point. Is it a problem if I double post this?

---

<div class="post-metadata">

**Author:** ![xgamerx](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/d2c977/32.png) [@xgamerx](https://www.ruby-forum.com/u/xgamerx)\
**Post date:** [August 1, 2008, 11:34am UTC](https://www.ruby-forum.com/t/improved-find-syntax-in-rails/144702/5 "2008-08-01T11:34:38Z")

</div>

On 1 Aug 2008, at 10:17, Nathan E. wrote:

> That’s a fair point. Is it a problem if I double post this?

Other than 7 generations of bad luck I don’t think anyone will mind 🙂

Fred
