Plugins - ez_where
Add to favoritesez_where maps ruby operators to sql ops. Like this:
articles = Article. find_where(:all, :include => :author) do |article, author| article.title =~ "%Foo Title%" author.any do name == 'Ezra' name == 'Fab' end end
:conditions => ["article.title LIKE ? AND (authors.name = ? OR authors.name = ?)", "%Foo Title%", "Ezra", "Fab"]
Basically here is the breakdown of how we map ruby operators to SQL operators:
foo == 'bar' #=> ["foo = ?", 'bar'] foo =~ '%bar' #=> ["foo LIKE ?", '%bar'] foo <=> (1..5) #=> ["foo BETWEEN ? AND ?", 1, 5] id === [1, 2, 3, 5, 8] #=> ["id IN(?)", [1, 2, 3, 5, 8]] <, >, >=, <= et all will just work like you expect.
There are many more features to this plugin. See the extensive test cases in the plugin for all available options.
Ezra Zygmuntowicz & Fabien Franzen
http://brainspl.at/articles/2006/01/30/i-have-been-busy
svn://rubyforge.org//var/svn/ez-where
Rails' (MIT)
Searching and Queries
