Hello,
I am looking for a way to map the result of a join (with crystal-db). Using DB::Serializable
or even another format I will map in post processing.
Example of what I am trying to do:
db.query_all(
"select users.* as user, posts.* as posts from users left join posts on posts.user_id = users.id",
as: {user: User, posts: Post?}
)
or maybe something like this:
db.query_all(
"select users.*, posts.* from users left join posts on posts.user_id = users.id",
as: {User, Post?}
)
But doesn’t work.
Note: User and Post include DB::Serializable
The idea is to get the result like:
- one instance
user.posts # => Array(Post)
- or two
user # => User
and posts # => Array(Post)` - even a Tuple (or NamedTuple) to do a post processing
if you know an example or a solution, it would be very useful.