Sorry for asking questions here but i couldn't find the answer in docs. I am joining two tables with nestTables: true and getting
[{
table1: {
fieldA: '...',
fieldB: '...',
},
table2: {
fieldA: '...',
fieldB: '...',
},
}, ...]
but i would like to get it in this format because it is more suitable for RESTful api:
[{
fieldA: '...',
fieldB: '...',
table2: {
fieldA: '...',
fieldB: '...',
},
}, ...]
is this possible with the api or i have to use Array.map to match desidered format?
It is currently not possible with the existing nestTables API. If you have an idea for how to implement this in the module, let us know your proposal :)
I'll see what I can do :)
I got it working. Passed object to nestTables with name of the table(object) that is parent(top level object).
If we, for example, JOIN two tables products and collections and pass
..{sql: ..., nestTables: {parent : 'products'}}..
we will get:
[{
fieldA: '...',
fieldB: '...',
fieldC: '...',
collections: {
fieldA: '...',
fieldB: '...',
},
}, ...]
this will also work with multiple selected tables as one will be parent and rest are nested inside this top level object.
I can make a pull request if this satisfies module design. @dougwilson
Most helpful comment
I got it working. Passed object to nestTables with name of the table(object) that is parent(top level object).
If we, for example, JOIN two tables products and collections and pass
..{sql: ..., nestTables: {parent : 'products'}}..we will get:
this will also work with multiple selected tables as one will be parent and rest are nested inside this top level object.
I can make a pull request if this satisfies module design. @dougwilson