Skip to content

Instantly share code, notes, and snippets.

@apneadiving
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apneadiving/15a3de9fa6d9031bedfd to your computer and use it in GitHub Desktop.
Save apneadiving/15a3de9fa6d9031bedfd to your computer and use it in GitHub Desktop.
where_values binding issue?
class Author::Work < AR::Base
scope :with_text, -> { where.not(text: nil) }
scope :started, -> { where(status: 0) }
scope :in_progress, -> { started.with_text }
end
> Author::Work.in_progress.to_sql
=> "SELECT \"author_works\".* FROM \"author_works\" WHERE \"author_works\".\"status\" = 0 AND (\"author_works\".\"text\" IS NOT NULL)"
> Author::Work.in_progress.where_values.map &:to_sql
=> ["\"author_works\".\"status\" = $1", "\"author_works\".\"text\" IS NOT NULL"]
# see the $1 ?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment