Hey!
I wonder if it is possible to do a select
or select_merge
in a join query.
User table: first_name
, last_name
Post table: title
, body
, user_id
Now, I want to join the user table into the post table. In addition, I want to use a fragment to compose the first_name
and last_name
of the user to a full_name
.
The result should be something like this:
%Post {
title: "",
body: "",
user: %User {
first_name: "",
last_name: "",
full_name: ""
}
}
When querying the user, I could do:
from u in User,
select_merge: %{full_name: fragment("concat(?, ' ', ? )", u.first_name, u.last_name)}
But how would I achieve such concatenation in a join
query?
The ecto select_merge
documentation says - Ecto.Query — Ecto v3.11.1
select_merge
cannot be used to set fields in associations, as associations are always loaded later, overriding any previous value.
So I wonder whether it is possible at all. Is there another to approach to get the query result I stated above?
Best regards