Skip to content

Commit

Permalink
Use the same database prefix as the existing rows when preloading via…
Browse files Browse the repository at this point in the history
… a lateral join
  • Loading branch information
sevenseacat committed Oct 13, 2020
1 parent 3ea0f68 commit 1c354b3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/dataloader/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -673,9 +673,12 @@ if Code.ensure_loaded?(Ecto) do

def preload_lateral([], _assoc, _query, _opts), do: []

def preload_lateral([%schema{} | _] = structs, assoc, query, repo, repo_opts) do
def preload_lateral([%schema{} = struct | _] = structs, assoc, query, repo, repo_opts) do
[pk] = schema.__schema__(:primary_key)

# Carry the database prefix across from already-loaded records if not already set
repo_opts = Keyword.put_new(repo_opts, :prefix, struct.__meta__.prefix)

assocs = expand_assocs(schema, [assoc])

inner_query =
Expand Down

0 comments on commit 1c354b3

Please sign in to comment.