T
TanStack3y ago
loud-coral

Pivot table / has_many relationship

Hey all. I have a table that is structured as:
create table Question {
id uuid,
question string,
}

create table Answer {
id uuid,
question_id uuid,
answer string
}
create table Question {
id uuid,
question string,
}

create table Answer {
id uuid,
question_id uuid,
answer string
}
one question HAS MANY answers. We're getting the data as:
{
questions: [{
id: 123,
question: "...",
answers: [{...}]
}, {
id: 123,
question: "...",
answers: [{...}]
}]
}
{
questions: [{
id: 123,
question: "...",
answers: [{...}]
}, {
id: 123,
question: "...",
answers: [{...}]
}]
}
I'd like the headers to be the "question" fields, and need to pivot answers to be row based. Is there an easy way to do this? Or any advice on how to solve it?
2 Replies
eastern-cyan
eastern-cyan3y ago
@nimo
loud-coral
loud-coralOP3y ago
@shadowshine1 ?

Did you find this page helpful?