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

Should it be allowed to generate live/html/json/... without attributes? #5714

Open
agonzalezro opened this issue Feb 6, 2024 · 2 comments
Open

Comments

@agonzalezro
Copy link
Contributor

agonzalezro commented Feb 6, 2024

Environment

  • Elixir version (elixir -v): 1.16.1
  • Phoenix version (mix deps): 1.17.1
  • Operating system: Sonoma

Actual behavior

After a generation without attributes:

mix phx.gen.live Todos Item items

and adding the routes I get an error on the view:

key :col not found in: %{
  __changed__: nil,
  __given__: %{
    __changed__: nil,
    action: [
      %{
        __slot__: :action,
        inner_block: #Function<5.76604854/2 in FooWeb.TodoLive.Index.render/1>
      },
      %{
        __slot__: :action,
        inner_block: #Function<6.76604854/2 in FooWeb.TodoLive.Index.render/1>
      }
    ],
    id: "todos",
    ...

Expected behavior

The error itself make sense, I wonder if there are cases when it's useful to use the generator without providing attributes or it's just an error.

Please, let me know if it's an error and I can try to provide a patch.

@josevalim
Copy link
Member

josevalim commented Feb 23, 2024

If there are no columns, maybe the generator should then use the id column as the initial column?

@agonzalezro
Copy link
Contributor Author

agonzalezro commented Feb 27, 2024

I am trying to understand if there is a real use case behind a generation without any attribute.

Fixing the table in the index is easy as you said by just showing the ID column. However, there are some other small changes that need to be done to make this work and I don't know if they are worthy. For example, in the FormComponent's save event it will be needed to support an empty object.

I am happy to do those changes to the generator if it helps, but I am leaning more toward the option of just fail if the phx.gen.live or others are being called without attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants