On Fri, Jan 14, 2022 at 9:29 AM 'Mike Pastore' via sequel-talk <
sequel-talk@googlegroups.com> wrote:

> Hi Jeremy,
>
> I have an `agent_role' enum type in my Postgres database, and a table with
> a `roles' column, type `agent_role[]'. I'd like to filter records in this
> table where the `roles' column contains a certain `agent_role'.
>
> This works:
>
>     .where('sales_representative'=>Sequel[:roles].pg_array.any) #
> => ('sales_representative' = ANY("roles"))
>
> But I can't seem to make this work (the terms get reversed and Postgres
> doesn't like it):
>
>     .where { 'sales_representative' =~ roles.pg_array.any } #
> => (ANY("roles") = 'sales_representative'))
>

This isn't a Sequel issue, but a Ruby issue.  string =~ arg calls arg =~
string (this is how String#=~ behaves in Ruby).

You can get the behavior you want by wrapping the string in a Sequel object:

 .where {Sequel['sales_representative'] =~ roles.pg_array.any }

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/CADGZSSe1vi1nSxrzLWC5ZF33B_gVYjUcFXDeLmfXTxUzrsysWQ%40mail.gmail.com.

Reply via email to