Jean Duarte
Jean Duarte

Reputation: 180

Best practices for Ecto Associations

When handling models with associations, what is the best practice to load associated models: to use Repo.preload explicitly or specifying associations that should be pre-loaded when defining a Query?

Upvotes: 4

Views: 911

Answers (1)

José Valim
José Valim

Reputation: 51369

They are equivalent so any approach is fine, really. Make it part of the query if you want to have everything in one place. Repo.preload/2 is useful when, for some reason, the query has already been performed.

Upvotes: 5

Related Questions