What about: Person.select(1).where(name: "Dennis").first.present?

On Sunday, February 21, 2021 at 1:43:34 p.m. UTC-5 [email protected] 
wrote:

> No positive predicate that I'm aware of. Negate the negative `empty?` for 
> the same result.
>
>     !Person.where(name: 'Dennis').empty?
>     # I, [2021-02-21T13:41:13.247556 #43387]  INFO -- : (0.000002s) SELECT 
> 1 AS one FROM people WHERE (name = 'Dennis') LIMIT 1
>     # => false
>
> On Sunday, February 21, 2021 at 1:03:17 PM UTC-5 [email protected] 
> wrote:
>
>> For now I do:
>>
>> Person.where(name: 'Dennis').count.positive? # took 0.1ms. any? did took 
>> 0.8ms due to full row select.
>>
>> But would like to know if there is a native method for this.
>>
>> On Sunday, February 21, 2021 at 7:28:54 PM UTC+3 [email protected] 
>> wrote:
>>
>>> Hi Jeremy,
>>>
>>> I was using to check if any record exists on table:
>>>
>>> Person.where(name: 'Dennis').any?
>>>
>>> But as far as i see in my logs, this fetch the whole record and 
>>> translated as:
>>>
>>> SELECT * FROM persons WHERE name = 'Dennis'
>>>
>>> How can I check existence (if any record available) without fetching 
>>> whole record(s)?
>>>
>>> Thanks,
>>> Dennis.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/57c45aa4-0610-4a66-9287-cc3bbfbe1042n%40googlegroups.com.

Reply via email to