Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/ecto/repo/queryable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,12 @@ defmodule Ecto.Repo.Queryable do

schema = head.__struct__
prefix = head.__meta__.prefix
source = head.__meta__.source

case schema.__schema__(:primary_key) do
[pk] ->
keys = Enum.map(structs, &get_pk!(&1, pk))
query = Query.from(x in schema, where: field(x, ^pk) in ^keys)
query = Query.from(x in {source, schema}, where: field(x, ^pk) in ^keys)
%{query | prefix: prefix}

pks ->
Expand Down
6 changes: 6 additions & 0 deletions test/ecto/repo_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ defmodule Ecto.RepoTest do
TestRepo.reload(struct_with_prefix)
assert_received {:all, %{prefix: %{key: :another}}}
end

test "respects source" do
struct_with_custom_source = put_meta(%MySchema{id: 2}, source: "custom_schema")
TestRepo.reload(struct_with_custom_source)
assert_received {:all, %{from: %{source: {"custom_schema", MySchema}}}}
end
end

defmodule DefaultOptionRepo do
Expand Down