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/db7c31c6-f694-495f-bcf9-b12a5ea7c1f5n%40googlegroups.com.

Reply via email to