Access to more Arel predicate types from where condition hash

I could use some eyes on #4368 Patch: Access to more Arel predicate types from where condition hash - Ruby on Rails - rails if anyone has the time.

Summary of the change:

Similar to PredicateBuilder's existing support for 'table.column' => 'value', this patch enables 'column#method' => 'value'.

For instance, Article.where('title#matches' => 'Hello%') generates SQL like:

SELECT "articles".* FROM "articles" WHERE ("articles"."title" LIKE 'Hello%')

Among other things, this change would prevent it from being necessary to resort to SQL strings in order to achieve something as simple as a a "published_at is not null" where clause.

  Article.where('published_at#noteq' => nil).to_sql   SELECT "articles".* FROM "articles" WHERE ("articles"."published_at" IS NOT NULL)

It plays nicely with scopes:

  scope :published, where('published_at#noteq' => nil)

In general, I don't see a whole lot of downsides to this... One thing that could perhaps be improved is the elimination of quote requirements around hash keys by method_missing on Symbol (:table.column), and an operator for method selection -- :column/:method maybe? I don't know, that syntax looks a bit goofy, too. I chose the # of its relationship to Object#method. Most likely for the same reasons the new routing strings were chosen.

Thanks,    Ernie

Thanks to a discussion with Pratik on #rails-contrib today, I decided to roll this into a gem instead:

Consider the request for feedback on the patch revoked. :slight_smile:


Maybe we should fork these kinds of gems into the Rails repo and point them out in the guides? In my view, we’ll eventually roll some of these solutions into Rails once they get robust, and used by more people, so let’s encourage that!

Yehuda Katz Developer | Engine Yard (ph) 718.877.1325