Skip to content
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

Fix generator default_types relying on map order #5907

Merged
merged 1 commit into from
Aug 27, 2024
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/mix/phoenix/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ defmodule Mix.Phoenix.Schema do
"""
def value(schema, field, value) do
schema.types
|> Map.fetch!(field)
|> Keyword.fetch!(field)
|> inspect_value(value)
end

Expand Down Expand Up @@ -492,7 +492,7 @@ defmodule Mix.Phoenix.Schema do
end

defp types(attrs) do
Enum.into(attrs, %{}, fn
Keyword.new(attrs, fn
{key, {:enum, vals}} -> {key, {:enum, values: translate_enum_vals(vals)}}
{key, {root, val}} -> {key, {root, schema_type(val)}}
{key, val} -> {key, schema_type(val)}
Expand Down
2 changes: 1 addition & 1 deletion priv/templates/phx.gen.embedded/embedded_schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule <%= inspect schema.module %> do
import Ecto.Changeset
alias <%= inspect schema.module %>

embedded_schema do <%= if !Map.equal?(schema.types, %{}) do %>
embedded_schema do <%= if !Enum.empty?(schema.types) do %>
<%= Mix.Phoenix.Schema.format_fields_for_schema(schema) %><% end %>
<%= for {_, k, _, _} <- schema.assocs do %> field <%= inspect k %>, <%= if schema.binary_id do %>:binary_id<% else %>:id<% end %>
<% end %> end
Expand Down
2 changes: 1 addition & 1 deletion test/mix/tasks/phx.gen.embedded_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Mix.Tasks.Phx.Gen.EmbeddedTest do
human_plural: "Nil",
human_singular: "Post",
attrs: [title: :string],
types: %{title: :string},
types: [title: :string],
embedded?: true,
defaults: %{title: ""}
} = schema
Expand Down
4 changes: 2 additions & 2 deletions test/mix/tasks/phx.gen.schema_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do
human_plural: "Posts",
human_singular: "Post",
attrs: [title: :string, tags: :map],
types: %{title: :string, tags: :map},
types: [title: :string, tags: :map],
optionals: [:tags],
route_helper: "post",
defaults: %{title: "", tags: ""},
Expand All @@ -53,7 +53,7 @@ defmodule Mix.Tasks.Phx.Gen.SchemaTest do
human_plural: "Posts",
human_singular: "Post",
attrs: [title: :string],
types: %{title: :string},
types: [title: :string],
route_helper: "api_v1_post",
defaults: %{title: ""},
} = schema
Expand Down