Skip to content

Commit

Permalink
Merge pull request #1021 from gjaldon/do-not-override-meta
Browse files Browse the repository at this point in the history
Ensure __meta__ is not overridden in build/3
  • Loading branch information
josevalim committed Oct 15, 2015
2 parents ca748bb + 1cddc90 commit 70f67f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ecto/model.ex
Expand Up @@ -109,7 +109,7 @@ defmodule Ecto.Model do
"""
def build(%{__struct__: model} = struct, assoc, attributes \\ %{}) do
assoc = Ecto.Association.association_from_model!(model, assoc)
assoc.__struct__.build(assoc, struct, attributes)
assoc.__struct__.build(assoc, struct, Dict.delete(attributes, :__meta__))
end

@doc """
Expand Down
5 changes: 5 additions & 0 deletions test/ecto/association_test.exs
Expand Up @@ -355,6 +355,11 @@ defmodule Ecto.AssociationTest do

# Overriding defaults
assert build(%Summary{id: 1}, :post, title: "Hello").title == "Hello"

# Should not allow overriding of __meta__
meta = %{__meta__: %{source: {nil, "posts"}}}
comment = build(%Post{id: 1}, :comments, meta)
assert comment.__meta__.source == {nil, "comments"}
end

test "assoc/2" do
Expand Down

0 comments on commit 70f67f4

Please sign in to comment.