Ecto preload in preload query

We have companies, users and a join table, called employees, which has additional metadata such as ‘salary’.

employees_query = from e in Employee, order_by: e.salary, preload: [:user]
company = Repo.preload(company, [employees: employees_query])

The preload: [:user] is not working here, I get an Ecto.Association.NotLoaded instead. Is this the wrong syntax for this query?

1 Like
query = from u in User, limit: 1, preload: :role
user = Repo.one query
iex(14)> user.role.name
"admin"

Should work.
Could you share schemas and whole output from iex -S mix?
Do you have data in User?

1 Like