support selecting a subset of a subquery as a struct#4678
support selecting a subset of a subquery as a struct#4678greg-rychlewski merged 3 commits intoelixir-ecto:masterfrom
Conversation
|
I don't think that integration test is failing due to my changes but there is something weird w/ the results, I can't see them or rerun the task. |
|
Feel free to squash. |
74aa800 to
b6d7b9b
Compare
|
Should be good to go 😄 |
|
One last nitpick and we can ship! |
| end | ||
|
|
||
| defp handle_subquery_struct(select, requested_fields, ix, query) do | ||
| available_fields = subquery_source_fields(select) |
There was a problem hiding this comment.
I'm not able to check atm but I believe error! prints the query so it might be unnecessary to include this in the message
There was a problem hiding this comment.
🤔 I don't think I'm currently adding the query to any error message, but maybe I'm missing it. Could you point out the line?
There was a problem hiding this comment.
oh sorry I meant that available_fields is only used here:
error!(query, "field `#{field}` in struct/2 is not available in the subquery. " <>
"Subquery only returns fields: #{inspect(available_fields)}")and i think it might be unnecessary because the error! function already prints the entire query. it raises Ecto.QueryError which takes care of it. so you are already told which fields exist in that way.
it's not a big deal either way it was just a tiny cleanup (if my assumptions are right)
There was a problem hiding this comment.
Ah, gotcha. I think I'd prefer this because when the query gets big (like in my current case) or involves multiple subqueries for example, it's not always entirely obvious. Listing the available fields I think will make it much clearer.
|
Done 🥳 |
|
thanks! |
|
🙇 |
This increases the general flexibility of subquery selecting. For example, there might be a case where you want to do something like this:
The
specialfield being filtered outside of the subquery requires selecting it from the subquery, but it doesn't need to be present in the response.That's a contrived example because you would just filter in the subquery, but real life has gotten me to this point in a more complicated scenario 😄