Skip to content

Commit

Permalink
Supplement preload docs (#4340)
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-rychlewski authored Dec 19, 2023
1 parent 9f5a24d commit ba2d748
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/ecto/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,16 @@ defmodule Ecto.Repo do
database.
In case the association was already loaded, preload won't attempt
to reload it.
to reload it. Preload assumes each association has the same nested
associations already loaded. If this is not the case, it is
possible to lose information. For example:
comment1 = TestRepo.preload(comment1, [author: [:permalink]])
TestRepo.preload([comment1, comment2], :author)
The first comment will lose its nested `:permalink` association because
the second comment does not have it preloaded. To avoid this, you must
preload the nested associations as well.
If you want to reset the loaded fields, see `Ecto.reset_fields/2`.
Expand Down

0 comments on commit ba2d748

Please sign in to comment.