Allow Relation.where with no arguments to be chained with new query methods `not`, `like`, and `not_like` #8365

wants to merge 2 commits into


None yet
3 participants

claudiob commented Nov 29, 2012

Similarly to #8332 this commit closes #5950 by making available three new methods not, like, and not_like that can be chained with a Relation.where with no (or nil) arguments.

The difference is that this commit follows the suggestion by José Valim #8332 (comment) to use a class and a builder, rather than a mixin, to implement WhereChain.

amatsuda and others added some commits Nov 5, 2012

Relation.where with no args can be chained with not, like, and not_like

  Model.where.not field: nil
  #=> "SELECT * FROM models WHERE field IS NOT NULL name: 'Jeremy%'
  #=> "SELECT * FROM models WHERE name LIKE 'Jeremy%'

this feature was originally suggested by Jeremy Kemper #5950 (comment)

Closes #5950
Transforms WhereChain from a mixin to a builder
This feature was originally suggested by José Valim #8332 (comment)

The original commit fddf9c2 by Akira Matsuda enabled the methods #not, #like,
and #not_like to be chained to a Relation.where with no args.
This commit maintains the same behavior, but requires using #where before
chaining any of the previous methods, which makes chaining clearer.

Closes #5950

jeremy commented Nov 29, 2012

Thank you for implementing, @claudiob. However, let's give the original author the honors ❤️

Please do open a PR with improvements after his work is merged!

@jeremy jeremy closed this Nov 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment