I have teams, and each team has users, so there is a connection table to associate users with teams as many, many relationships, here are my models:
defmodule App.Team do use App.Web, :model schema "teams" do field :owner_id, :integer has_many :team_users, {"team_user", App.TeamUser} end end defmodule App.User do use App.Web, :model schema "users" do
And here is the merge model:
defmodule App.TeamUser do use App.Web, :model @primary_key false schema "team_user" do belongs_to :user, App.User belongs_to :team, App.Team end end
If I run a query to get all user commands with all the given commands, for example:
teams_users = from(t in Team, where: t.owner_id == ^user_id) |> Repo.all() |> Repo.preload(:team_users)
I get this log:
[%App.Team{__meta__: #Ecto.Schema.Metadata<:loaded>, id: 1, is_base_team: true, owner_id: 3, team_users: [%App.TeamUser{__meta__: #Ecto.Schema.Metadata<:loaded>, team: #Ecto.Association.NotLoaded<association :team is not loaded>, team_id: 1, user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: 3}, %App.TeamUser{__meta__: #Ecto.Schema.Metadata<:loaded>, team: #Ecto.Association.NotLoaded<association :team is not loaded>, team_id: 1, user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: 4}, %App.TeamUser{__meta__: #Ecto.Schema.Metadata<:loaded>, team: #Ecto.Association.NotLoaded<association :team is not loaded>, team_id: 1, user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: 5}]}]
In the log I received a command with id 1, and all its users with identifiers: (3, 4, 5) But why did I get user: #Ecto.Association.NotLoaded<association :user is not loaded> ? I did not ask to load the user by this identifier in any way .. so why did I get such a warning?
I am using {:phoenix_ecto, "~> 3.0-rc}