I have a left outer join
query and I would like to nest the result when I execute the query from the .all
method. At the moment I am only able to return the result in a flat hash but I would like a nested hash so the join table name is the next level in the hash. Is this even possible within Sequel?
I have product
and meta
tables and the Sequel command is via graph so the columns are aliased, and look like this:
db[:product].graph(:meta, {product_id: : product_id}, {join_type: :left_outer}).all
What's annoying with the graph command is it will only alias columns if it matches the main table. Is there a way of making sure it changes all the columns as you'll see that the quantity
column hasn't got a prefix of meta_
?
If this is possible then I suppose I could modify the hash manually by moving the key => values
into a separate hash that is nested by matching the prefix (meta_) of the keys.
This is what is currently being returned but I would like the nested hash instead:
Currently:
{
id: 1,
name: 'Shave',
product_id: 123,
meta_id: 1,
meta_product_id: 123,
quantity: 2
}
What I'd like to see:
{
id: 1,
name: 'Shave',
product_id: 123,
meta: {
id: 1,
product_id: 123,
quantity: 2
}
}