Skip to content

Instantly share code, notes, and snippets.

@robdimarco
Created February 11, 2012 15:57
Show Gist options
  • Save robdimarco/1801297 to your computer and use it in GitHub Desktop.
Save robdimarco/1801297 to your computer and use it in GitHub Desktop.
class Article < ActiveRecord::Base
default_scope where(:published => true)
end
> Article.all
SQL -> SELECT "articles".*
FROM "articles" WHERE "articles"."published" = 't'
> Article.where(title: "a")
SQL -> SELECT "articles".*
FROM "articles" WHERE "articles"."published" = 't'
AND "articles"."title" = 'a'
> Article.where(published:false)
SQL -> SELECT "articles".*
FROM "articles" WHERE "articles"."published" = 'f
> Article.where(published:nil)
SQL -> SELECT "articles".*
FROM "articles" WHERE "articles"."published" IS NULL
> Article.instance_eval{
> with_exclusive_scope{
> Article.where(title: "a")
> }
> }
SQL -> SELECT "articles".*
FROM "articles" WHERE "articles"."title" = 'a'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment