Skip to content
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
12 changes: 12 additions & 0 deletions lib/mix/tasks/phx.gen.live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ defmodule Mix.Tasks.Phx.Gen.Live do
Mix.Phoenix.ensure_live_view_compat!(__MODULE__)

{context, schema} = Gen.Context.build(args)
validate_context!(context)

Gen.Context.prompt_for_code_injection(context)

binding = [context: context, schema: schema, inputs: inputs(schema)]
Expand All @@ -129,6 +131,16 @@ defmodule Mix.Tasks.Phx.Gen.Live do
|> print_shell_instructions()
end

defp validate_context!(context) do
cond do
context.schema.singular == "form" ->
Gen.Context.raise_with_help("cannot use form as the schema name because it conflicts with the LiveView assigns!")

true ->
:ok
end
end

defp prompt_for_conflicts(context) do
context
|> files_to_be_generated()
Expand Down
6 changes: 6 additions & 0 deletions test/mix/tasks/phx.gen.live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,10 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do
end
end
end

test "raises on schema named form" do
assert_raise Mix.Error, ~r/cannot use form as the schema name because it conflicts with the LiveView assigns/, fn ->
Mix.Tasks.Phx.Gen.Live.run(~w(Blog Form forms title:string))
end
end
end
Loading