Re: .where & Order

2020-02-24 Thread Jeremy Evans
On Monday, February 24, 2020 at 12:42:44 PM UTC-8, BeeRich33 wrote:
>
> I ran across the following, which is confusing:
>
> DB[:table].where{(bravo > 100) & {alpha_status: 'active'}} # works
> DB[:table].where{{alpha_status: 'active'} & (bravo > 100)} # error
>
> It seems there is a preference.  I know they're in the same block, but are 
> they not handled independently before the AND?
>

Hash#& is not defined by default, which is why you get the NoMethodError.  
 If you load the core_extensions extension, the second example also works.

You could also wrap the hash in the second example in a Sequel object:

  DB[:table].where{Sequel[{alpha_status: 'active'}] & (bravo > 100)}

or you could use an alternative method of expressing equality:

  DB[:table].where{(alpha_status =~ 'active') & (bravo > 100)}

In both of those cases, the core extensions are not required.

Thanks,
Jeremy

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/a908223b-a2f5-4ac3-873e-636fe86d27b4%40googlegroups.com.


.where & Order

2020-02-24 Thread BeeRich33
I ran across the following, which is confusing:

DB[:table].where{(bravo > 100) & {alpha_status: 'active'}} # works
DB[:table].where{{alpha_status: 'active'} & (bravo > 100)} # error

It seems there is a preference.  I know they're in the same block, but are 
they not handled independently before the AND?

Cheers

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/c31abb32-ca2c-421f-b982-c10009c4b80e%40googlegroups.com.