Skip to content

Instantly share code, notes, and snippets.

@rasmar
Created January 3, 2018 10:50
Show Gist options
  • Select an option

  • Save rasmar/2695f555d34c0d85e0b566a04d557ca7 to your computer and use it in GitHub Desktop.

Select an option

Save rasmar/2695f555d34c0d85e0b566a04d557ca7 to your computer and use it in GitHub Desktop.
Query Objects

WHY USE

  1. Slim-down models / controllers
  2. Dissect big queries
  3. Make testing queries easier

WHAT IS IT

  1. It's a PORO
  2. Overrides ActiveRecord standard query methods like all
  3. Query objects can be composed (as long as they return relation)
  4. QUery objects can be extended by inheritance
  5. Represents only a query, not a business logic

Things to remember

  1. Original article
  2. Method extending
  3. Method presence_in
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment