Re: [Rails-core] Re: [Feature][ActiveRecord] Find records with present attribute value more easily

2018-12-18 Thread Tom Rossi
I like the idea of adding this to the where chain so you could do *Person.where.blank(:name)* and *Person.where.present(:name)*. Joshua, let me know if you want to work together on a PR. On Sat, Dec 8, 2018 at 12:01 PM DHH wrote: > I agree that a double negative is iffy. But I don't like

[Rails-core] Re: [Feature][ActiveRecord] Find records with present attribute value more easily

2018-12-08 Thread DHH
I agree that a double negative is iffy. But I don't like present on the root. What I do like is: Person.where.present(:name) – so that #present on where becomes a modifier like #not. I would have to have the same semantics as Object#present?, though. So that means that both nil and empty would

Re: [Rails-core] Re: [Feature][ActiveRecord] Find records with present attribute value more easily

2018-12-07 Thread Sachin Mudgal
Personally, if I would ever like to change it, I will go for something like `Person.where(:name).is_not(nil)` or `Person.where(:name).is('Pikachu')` or `Person.where(:name).is_not(like: ['Pikachu', 'Raichu'])` etc.. Otherwise, I feel it already fine enough. On Fri, Dec 7, 2018 at 2:47 PM Anders

[Rails-core] Re: [Feature][ActiveRecord] Find records with present attribute value more easily

2018-12-07 Thread Anders Lemke
I've personally missed the `.present?`-functionality from `Object#present?` for querying my models several times. So I would argue, that in order to use

Re: [Rails-core] Re: [Feature][ActiveRecord] Find records with present attribute value more easily

2018-12-06 Thread JP Duffy
I don't think "having" is a good idea since it already means something else in SQL: https://en.wikipedia.org/wiki/Having_(SQL) On Thursday, December 6, 2018 at 7:27:20 AM UTC-6, Tom Rossi wrote: > > What about using "having"? > > Person.having(:name) > > On Thu, Dec 6, 2018 at 3:28 AM Greg

[Rails-core] Re: [Feature][ActiveRecord] Find records with present attribute value more easily

2018-12-06 Thread Filipe W. Lima
I personally use `where.not` and find it clear enough as it its. `.exists` doesn't seem like a good name because it can confused with current `exists?`: https://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-exists-3F On Wednesday, December 5, 2018 at 10:42:30 PM UTC-3,

Re: [Rails-core] Re: [Feature][ActiveRecord] Find records with present attribute value more easily

2018-12-06 Thread Kasper Timm Hansen
I don’t think these examples have much sway and the problem itself seems sufficiently solved by `where.not(name: nil)` to me. It’s clearer and does map nicely onto the resulting SQL. Yes, sometimes Rails does relish syntactic sugar but that’s when it aids clarity. PS. `having` is already

Re: [Rails-core] Re: [Feature][ActiveRecord] Find records with present attribute value more easily

2018-12-06 Thread Matt Norton
I like "having". It reads more expressively than "present" and "exists". Could provide an option for including/excluding empty strings: Person.having(:name, empty_strings: true) By default, should it include or exclude empty strings? Excluding nil and empty strings is probably more often the

Re: [Rails-core] Re: [Feature][ActiveRecord] Find records with present attribute value more easily

2018-12-06 Thread Andrew Kaspick
class ApplicationRecord < ActiveRecord::Base scope :not_blank, ->(field) { where.not(field => nil) } # or where.not(field => ['',nil]) depending on your needs end And you're done. As you can see above, what does 'exists' or 'present' mean? Not nil, or not nil and an empty string or maybe just

Re: [Rails-core] Re: [Feature][ActiveRecord] Find records with present attribute value more easily

2018-12-06 Thread Tom Rossi
What about using "having"? Person.having(:name) On Thu, Dec 6, 2018 at 3:28 AM Greg Navis wrote: > Using "present' might be confusing with the presence validation which is > something different (a blank string is not present but is not nil either). > > Best regards > Greg Navis > > -- > You

Re: [Rails-core] Re: [Feature][ActiveRecord] Find records with present attribute value more easily

2018-12-06 Thread Greg Navis
Using "present' might be confusing with the presence validation which is something different (a blank string is not present but is not nil either). Best regards Greg Navis -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe

[Rails-core] Re: [Feature][ActiveRecord] Find records with present attribute value more easily

2018-12-05 Thread Matt Norton
Alternative: Person.exists(:name) On Wednesday, December 5, 2018 at 6:30:12 PM UTC-5, Matt Norton wrote: > > Instead of: > Person.where.not(name: nil) > > Use: > Person.present(:name) > > Avoids double negative and verbosity. > > I'd be happy to contribute if there's interest in this! > --