New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveRecord support for where_not #5950

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
@jacobo

jacobo commented Apr 24, 2012

It's incredibly annoying to negate things in Active Record! I can do:

Person.where(:name => "Jacob")

but to negate it, I'd have to use a SQL fragment like this:

Person.where("name <> ? ", "Jacob")

I want support:

Person.where(:name.not => "Jacob")

(see: #5948)

But barring that, let's support:

Person.where_not(:name => "Jacob")
@jeremyf

This comment has been minimized.

Show comment
Hide comment
@jeremyf

jeremyf May 9, 2012

Contributor

Also closes #5160

Contributor

jeremyf commented May 9, 2012

Also closes #5160

@jeremyf

This comment has been minimized.

Show comment
Hide comment
@jeremyf

jeremyf May 9, 2012

Contributor

@jacobo Unfortunatley the tests do not cleanly merge with master. Could you resolve the merge and let me know.

Contributor

jeremyf commented May 9, 2012

@jacobo Unfortunatley the tests do not cleanly merge with master. Could you resolve the merge and let me know.

@jacobo

This comment has been minimized.

Show comment
Hide comment
@jacobo

jacobo May 9, 2012

cool, I'm glad to see interest. Will work on this soon.

How do you feel about a "where_like" method being included also?

jacobo commented May 9, 2012

cool, I'm glad to see interest. Will work on this soon.

How do you feel about a "where_like" method being included also?

@jeremyf

This comment has been minimized.

Show comment
Hide comment
@jeremyf

jeremyf May 9, 2012

Contributor

@jacobo Get the rebase passing, and keep the pull request to a single focus; If the rails core team merges the "where_not" then by all means pursue the "where_like"

Contributor

jeremyf commented May 9, 2012

@jacobo Get the rebase passing, and keep the pull request to a single focus; If the rails core team merges the "where_not" then by all means pursue the "where_like"

@jeremy

This comment has been minimized.

Show comment
Hide comment
@jeremy

jeremy May 9, 2012

Member

Perhaps a Model.where with no args should be chainable: Model.where.not field: nil or Model.where.like name: 'John%'

Member

jeremy commented May 9, 2012

Perhaps a Model.where with no args should be chainable: Model.where.not field: nil or Model.where.like name: 'John%'

@tinogomes

This comment has been minimized.

Show comment
Hide comment
@tinogomes

tinogomes May 10, 2012

Contributor

where should be chainable. I like it!

Contributor

tinogomes commented May 10, 2012

where should be chainable. I like it!

@amatsuda

This comment has been minimized.

Show comment
Hide comment
@amatsuda

amatsuda Jun 21, 2012

Member

Perhaps a Model.where with no args should be chainable: Model.where.not field: nil or Model.where.like name: 'John%'

I added this feature to my existing "everywhere" gem as a proof of concept. amatsuda/everywhere@v1.0.1...v2.0.0
You can try this syntax just by adding 'everywhere' to your existing Rails 3 or 4 app's Gemfile.

@jeremy
Does this implementation satisfy your spec?

@tenderlove @jonleighton
And of course I'm willing to push this feature into AR core. Any thoughts? Shall I go ahead and send a PR?

Member

amatsuda commented Jun 21, 2012

Perhaps a Model.where with no args should be chainable: Model.where.not field: nil or Model.where.like name: 'John%'

I added this feature to my existing "everywhere" gem as a proof of concept. amatsuda/everywhere@v1.0.1...v2.0.0
You can try this syntax just by adding 'everywhere' to your existing Rails 3 or 4 app's Gemfile.

@jeremy
Does this implementation satisfy your spec?

@tenderlove @jonleighton
And of course I'm willing to push this feature into AR core. Any thoughts? Shall I go ahead and send a PR?

@tenderlove

This comment has been minimized.

Show comment
Hide comment
@tenderlove

tenderlove Jun 21, 2012

Member

@amatsuda seems good. I'd rather we have chainable where than monkeypatch symbol! 👍

Member

tenderlove commented Jun 21, 2012

@amatsuda seems good. I'd rather we have chainable where than monkeypatch symbol! 👍

@jeremy

This comment has been minimized.

Show comment
Hide comment
@jeremy

jeremy Jun 21, 2012

Member

@amatsuda Yes, very nice! Clean implementation, too. 👍

Member

jeremy commented Jun 21, 2012

@amatsuda Yes, very nice! Clean implementation, too. 👍

@carlosantoniodasilva

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva

carlosantoniodasilva Jun 21, 2012

Member

@amatsuda really cool, thanks for that :)

Member

carlosantoniodasilva commented Jun 21, 2012

@amatsuda really cool, thanks for that :)

@carlosantoniodasilva

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva

carlosantoniodasilva Aug 22, 2012

Member

@amatsuda do you have any thoughts whether we're going to be able add support for this? Thanks

Member

carlosantoniodasilva commented Aug 22, 2012

@amatsuda do you have any thoughts whether we're going to be able add support for this? Thanks

@amatsuda

This comment has been minimized.

Show comment
Hide comment
@amatsuda

amatsuda Aug 22, 2012

Member

@carlosantoniodasilva Yeah, I'm already having a working branch in my local machine. I'll add some tests and documents, then PR within few days.

Member

amatsuda commented Aug 22, 2012

@carlosantoniodasilva Yeah, I'm already having a working branch in my local machine. I'll add some tests and documents, then PR within few days.

@nijikon

This comment has been minimized.

Show comment
Hide comment
@nijikon

nijikon commented Aug 22, 2012

+1

@carlosantoniodasilva

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva

carlosantoniodasilva Aug 22, 2012

Member

@amatsuda alright, great! That'd be a great addition for sure :)

Member

carlosantoniodasilva commented Aug 22, 2012

@amatsuda alright, great! That'd be a great addition for sure :)

@jeroeningen

This comment has been minimized.

Show comment
Hide comment
@jeroeningen

jeroeningen commented Aug 22, 2012

👍

@jonleighton

This comment has been minimized.

Show comment
Hide comment
@jonleighton

jonleighton Sep 7, 2012

Member

Chainable where also gets a 👍 from me

Member

jonleighton commented Sep 7, 2012

Chainable where also gets a 👍 from me

@sikachu

This comment has been minimized.

Show comment
Hide comment
@sikachu

sikachu Sep 7, 2012

Member

@amatsuda すごい!

Would you mind finish up the test, doc change, so we can get this bad boy in before Rails 4 release? :D

Member

sikachu commented Sep 7, 2012

@amatsuda すごい!

Would you mind finish up the test, doc change, so we can get this bad boy in before Rails 4 release? :D

@kostyantyn

This comment has been minimized.

Show comment
Hide comment
@kostyantyn

kostyantyn Sep 22, 2012

What are you thinking about implementation of #gt, #gte and etc methods which mongoid orm has. As for me, this syntax is better than "where_#{method_name}"

kostyantyn commented Sep 22, 2012

What are you thinking about implementation of #gt, #gte and etc methods which mongoid orm has. As for me, this syntax is better than "where_#{method_name}"

@frodsan

This comment has been minimized.

Show comment
Hide comment
@frodsan

frodsan Oct 27, 2012

Contributor

@amatsuda Hi, did you open a pull request with your implementation? Can we close this PR? Thanks.

Contributor

frodsan commented Oct 27, 2012

@amatsuda Hi, did you open a pull request with your implementation? Can we close this PR? Thanks.

claudiob added a commit to claudiob/rails that referenced this pull request Nov 29, 2012

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

  Model.where.not field: nil
  #=> "SELECT * FROM models WHERE field IS NOT NULL

  Model.where.like name: 'Jeremy%'
  #=> "SELECT * FROM models WHERE name LIKE 'Jeremy%'

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

Closes #5950

claudiob added a commit to claudiob/rails that referenced this pull request Nov 29, 2012

Transforms WhereChain from a mixin to a builder
This feature was originally suggested by José Valim rails#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

amatsuda added a commit to amatsuda/rails that referenced this pull request Nov 29, 2012

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

  Model.where.not field: nil
  #=> "SELECT * FROM models WHERE field IS NOT NULL

  Model.where.like name: 'Jeremy%'
  #=> "SELECT * FROM models WHERE name LIKE 'Jeremy%'

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

Closes #5950
@jeremy

This comment has been minimized.

Show comment
Hide comment
@jeremy

jeremy Nov 29, 2012

Member

Moved to #8332

Member

jeremy commented Nov 29, 2012

Moved to #8332

@jeremy jeremy closed this Nov 29, 2012

amatsuda added a commit to amatsuda/rails that referenced this pull request Nov 29, 2012

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

  Model.where.not field: nil
  #=> "SELECT * FROM models WHERE field IS NOT NULL

  Model.where.like name: 'Jeremy%'
  #=> "SELECT * FROM models WHERE name LIKE 'Jeremy%'

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

Closes #5950
@Alamoz

This comment has been minimized.

Show comment
Hide comment
@Alamoz

Alamoz Aug 16, 2013

What about when mixing WHERE and NOT clauses? Tried chaining them, which doesn't work. Don't see any example of combining/chaining where and where.not anywhere in the documentation.

Alamoz commented Aug 16, 2013

What about when mixing WHERE and NOT clauses? Tried chaining them, which doesn't work. Don't see any example of combining/chaining where and where.not anywhere in the documentation.

@robin850

This comment has been minimized.

Show comment
Hide comment
@robin850

robin850 Aug 16, 2013

Member

@Alamoz : What about this example?

Member

robin850 commented Aug 16, 2013

@Alamoz : What about this example?

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