Separating results of join into objects of each type
Hey guys, I'm curious if anyone knows a way to unmerge the results of a join into objects of both types. For example, if you have a table User and table Bio, and query a single row which joins those two, the result is an a flat object with keys from both tables. What I'd like to do is separate the result into a User object and Bio object.
Solutions that work but I don't love:
1. manually extracting values from the object based on the current schema. (future changes to schema will break this, so I'd like to avoid that)
2. Multiple database queries for each object (this lengthens load times, which isn't a great solution for me either).
Let me know what you guys think and if you were able to find a good solution for this, or if I should just bite the bullet and go with solution 1.
2 Replies
Solution
Thanks @koskimas, to summarize the solution referenced from the docs, the idea is to coalesce the results as json so that you can extract different kinds of data from a single query. Makes code a little messier, but solves the problem nicely.