Skip to content

Make Repo.reload respect source #4510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions lib/ecto/repo/queryable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,12 @@ defmodule Ecto.Repo.Queryable do
assert_structs!(structs)

schema = head.__struct__
prefix = head.__meta__.prefix
%{prefix: prefix, source: source} = head.__meta__

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
Loading