SQL vs Ecto optimization/translation help

Parting thought, as I start to try this simplifying… I suspect I can make the query work, but I also beleive the shape of the data will be exactly the opposite what I want, and it may make for some very ugly code manually constructing structs or something to rearrange data how I want… I hoped the group_by clause in Ecto would flip things around to hand me back the CreditType structs I want, with the stocks and foods for them loaded up, but I’m pretty sure that was a delusion on my part because I didn’t understand group by correctly or something… is there anyway, given a bunch of sql data, to control how ecto instantiates the structs out of it? I start this query with from stocks in Stock, and so I’m pretty confident what I get out will be a list of Stock structs, but thats not what I want.. I want a list of CreditType, containing the stocks as a relation… I sort of lost focus on that while thinking about how to reproduce this SQL query as Ecto, but without that, I think I have to, in memory in elixir, do all kinds of weird acrobatics with the stocks that come back, shoving them into a map or struct based on which credit type’s they have present… which I can do, but just confirmed there’s not a better way.