Hello everyone,
currently I’m working on a Rocket REST API and I use Diesel for my database.
For simplicity I use the JSON format to show my problem.
When I make a GET requests I request an event that has a many to many relationship with a discipline. The output that I get from my query is something like:
{
event: “super indoor event”,
discipline: “dart”
}
{
event: “super indoor event”,
discipline: “football”
}
The structure that I really want is
{
event: “super indoor event”,
discipline: [“dart”, “football”],
}
The object that I currently use to load the data is the following:
#[derive(Queryable, Debug, Serialize)]
pub struct QueryResult {
pub event: String,
pub discipline: String,
}
I’m wondering if it’s doable to achieve something like:
#[derive(Queryable, Debug, Serialize)]
pub struct QueryResult {
pub event: String,
pub discipline: Vector<DisciplineResult>,
}
where the Vector contains multiple disciplines.
At the moment I use the following logic to load the data:
match join.load::<QueryResult>(connection) {
Ok(result) => Ok(result),
Err(_) => Err(()),
}
But this doesn’t work of course when I include the Vector.
I found this discussion: Link to Diesel Forum but I don’t know how to use the grouped by in this context.
I really appreciate your help.