Skip to content

Commit

Permalink
chore: Credo refactoring opportunity
Browse files Browse the repository at this point in the history
  • Loading branch information
doomspork committed Jan 18, 2024
1 parent 01c8eac commit a31e5b1
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lib/ex_machina/ecto.ex
Expand Up @@ -275,18 +275,10 @@ defmodule ExMachina.Ecto do
Enum.reduce(associations, record, fn association_name, record ->
association = struct.__schema__(:association, association_name)

case association do
%{__struct__: Ecto.Association.BelongsTo} ->
case Map.get(record, association_name) do
belongs_to = %{__meta__: %{__struct__: Ecto.Schema.Metadata, state: :loaded}} ->
set_belongs_to_primary_key(record, belongs_to, association)

_ ->
record
end

_ ->
record
with %{__struct__: Ecto.Association.BelongsTo} <- association,
%{__meta__: %{__struct__: Ecto.Schema.Metadata, state: :loaded}} = belongs_to <-
Map.get(record, association_name) do
set_belongs_to_primary_key(record, belongs_to, association)
end
end)
end
Expand Down

0 comments on commit a31e5b1

Please sign in to comment.