How to use task phx.gen.html to generate CRUD that use two tables from database?

I need generate a crud that use two tables from Database.

Table 1: State(Primary key idState)
Table 2: City(Primary key idCity, foreign key: idState)

Actually I using command at docker console:

mux phx,gen,html Entitys state states [paremeters to relation two tables]

thanks for advice.

1 Like

Have you checked embedded schemas?
Check this article to see an example as to how embedded schemas are used to manipulate multiple database schemas:

I like them because they also simplify the code in the controller side to a great extent as well.

1 Like

Thanks kurtz.

The solution was more simple.

mix phx.gen.html
city_id:references:schema_city
sate_id:references:state_city
I will read the article.

2 Likes