I’ve got two tables (articles and tags) that have a one-to-many relationship.
I remember seeing somewhere that I can create nested objects/arrays/etc from that relationship. The output of which I would like in a format such as (in JSON format):
{1 : {
id : 1,
title : 'article title',
tags : ({
id : 16,
tagname : 'first tag'
},{
id : 23,
tagname : 'another tag'
})
}
I’m creating an internal knowledge base system with a list view similar to the front page of stack overflow (that’s the way I’d like to display the tags).
How would I go about doing this? A subquery? Thanks.
If I understand your question correctly you’re looking for the
SelectManyfunction which lets you ‘unroll’ nested structures like yours.SelectManyis indeed executed in Query syntax by a sub-query:In method form: