Skip to content

Commit

Permalink
Tests appear green
Browse files Browse the repository at this point in the history
  • Loading branch information
soundmonster committed May 19, 2021
1 parent 4c2f560 commit e60211f
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/ecto/changeset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2763,7 +2763,7 @@ defmodule Ecto.Changeset do
constraint = opts[:name] ||
case get_assoc(changeset, assoc) do
%Ecto.Association.BelongsTo{owner_key: owner_key} ->
"#{get_source(changeset)}_#{owner_key}_fkey"
"#{get_source(changeset)}_#{atom_concat owner_key}_fkey"
other ->
raise ArgumentError,
"assoc_constraint can only be added to belongs to associations, got: #{inspect other}"
Expand Down Expand Up @@ -2814,7 +2814,7 @@ defmodule Ecto.Changeset do
case get_assoc(changeset, assoc) do
%Ecto.Association.Has{cardinality: cardinality,
related_key: related_key, related: related} ->
{opts[:name] || "#{related.__schema__(:source)}_#{related_key}_fkey",
{opts[:name] || "#{related.__schema__(:source)}_#{atom_concat related_key}_fkey",
message(opts, no_assoc_message(cardinality))}
other ->
raise ArgumentError,
Expand Down Expand Up @@ -3000,6 +3000,12 @@ defmodule Ecto.Changeset do
_ -> acc
end
end

defp atom_concat(atoms) do
atoms
|> Enum.map(&to_string/1)
|> Enum.join("_")
end
end

defimpl Inspect, for: Ecto.Changeset do
Expand Down

0 comments on commit e60211f

Please sign in to comment.