mercredi 8 juin 2022

Ruby - Convert SQL unnest to Arel

How can I convert the following query into Arel? I want to define a where condition using arel.

select * from tenants where id in (select a.id::int from tenants t2 cross join unnest(string_to_array(t2.ancestry, '/')) as a(id) where t2.id = 39);

Here is how the table output looks like:

-[ RECORD 1 ]-------------+------------------
id                        | 39
domain                    |
subdomain                 |
name                      | Child_Teanant_201
login_text                |
logo_file_name            |
logo_content_type         |
logo_file_size            |
logo_updated_at           |
login_logo_file_name      |
login_logo_content_type   |
login_logo_file_size      |
login_logo_updated_at     |
ancestry                  | 1/35
divisible                 | t
description               | Child_Teanant_201
use_config_for_attributes | f
default_miq_group_id      | 51
source_type               |
source_id                 |

Aucun commentaire:

Enregistrer un commentaire