Question about scaffolding

Hey there,

I am trying to make a simple crud application with phoenix only, and I found this guide: https://medium.com/@pngarland/scaffold-out-a-phoenix-application-2d335c25d433
first we would generate a scheme for example: mix phx.gen.schema Team teams name
and then generate the views: mix phx.gen.html Web Team teams name
would it be possible to then generate users similarly with a field that holds a reference to a team that they could be in?
mix phx.gen.schema User users name team ?
or how do we define relations between the table here?
Also would it be possible that when we create a user we would see all of the team that they could be added to?

Thank you

The docs for phx.gen.schema has an example with relationships:

The generator also supports references, which we will properly associate the
given column to the primary key column of the referenced table:

mix phx.gen.schema Blog.Post blog_posts title user_id:references:users

Edit: Sorry, looks like that generator doesn’t include the ecto relationships, only foreign key references.

The Ecto Association Guide covers adding associations.

1 Like

Thanks dude

Hey, I got the association set up, according to the guide, and i generated the views too, but how could I make it so that when I create a user I could choose from the existing teams to add them to? To have a reference?