Although I am passing the query to repository inspired by this answer like this:
teams_users = Repo.all (from(t in Team, where: t.owner_id == ^user_id))
|> Enum.each( &team_users/1 )
def team_users (team) do
%{id: id} = team
Repo.all (from(tu in TeamUser, where: tu.team_id == ^id))
end
However, I got this error:
[error] GenServer #PID<0.450.0> terminating
** (Protocol.UndefinedError) protocol Enumerable not implemented for #Ecto.Query<from t in App.Team, where: t.owner_id == ^1>
(elixir) lib/enum.ex:1: Enumerable.impl_for!/1
(elixir) lib/enum.ex:116: Enumerable.reduce/3
(elixir) lib/enum.ex:1477: Enum.reduce/3
(elixir) lib/enum.ex:609: Enum.each/2
(App) web/channels/user_channel.ex:93: App.UserChannel.handle_in/3
(phoenix) lib/phoenix/channel/server.ex:223: Phoenix.Channel.Server.handle_info/2
(stdlib) gen_server.erl:615: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:681: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
What I am trying to do is to get all the teams, then get the users of each team, then I expect to have all the users in one array.
Do I miss something? any advice? is there a better way to achieve this?