Skip to content

Instantly share code, notes, and snippets.

@jlebrech
Created April 5, 2012 12:40
Show Gist options
  • Save jlebrech/2310776 to your computer and use it in GitHub Desktop.
Save jlebrech/2310776 to your computer and use it in GitHub Desktop.
Arel subqueries
t=Ticket.arel_table # the arel table to extract subqueries from
if params[:title].length > 0 then
sqla = t[:title].matches("%#{params[:title]}%")
else
sqla = nil
end
if params[:from].length > 0 then
sqlb = t[:from].matches("%#{params[:from]}%")
else
sqlb = nil
end
if params[:includes].length > 0 then
sqlc = t[:includes].matches("%#{params[:includes]}%")
else
sqlc = nil
end
if params[:excludes].length > 0 then
sqld = t[:excludes].matches("%#{params[:excludes]}%")
else
sqld = nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment