Skip to content

Commit 69aad7e

Browse files
committed
raise when using form as schema name in phx.gen.live
Closes #5871.
1 parent 278cd45 commit 69aad7e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/mix/tasks/phx.gen.live.ex

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ defmodule Mix.Tasks.Phx.Gen.Live do
116116
Mix.Phoenix.ensure_live_view_compat!(__MODULE__)
117117

118118
{context, schema} = Gen.Context.build(args)
119+
validate_context!(context)
120+
119121
Gen.Context.prompt_for_code_injection(context)
120122

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

134+
defp validate_context!(context) do
135+
cond do
136+
context.schema.singular == "form" ->
137+
Gen.Context.raise_with_help("cannot use form as the schema name because it conflicts with the LiveView assigns!")
138+
139+
true ->
140+
:ok
141+
end
142+
end
143+
132144
defp prompt_for_conflicts(context) do
133145
context
134146
|> files_to_be_generated()

test/mix/tasks/phx.gen.live_test.exs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,4 +433,10 @@ defmodule Mix.Tasks.Phx.Gen.LiveTest do
433433
end
434434
end
435435
end
436+
437+
test "raises on schema named form" do
438+
assert_raise Mix.Error, ~r/cannot use form as the schema name because it conflicts with the LiveView assigns/, fn ->
439+
Mix.Tasks.Phx.Gen.Live.run(~w(Blog Form forms title:string))
440+
end
441+
end
436442
end

0 commit comments

Comments
 (0)