benonymus

benonymus

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

Most Liked

mbuhot

mbuhot

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.

Last Post!

benonymus

benonymus

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?

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

Other popular topics Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36820 110
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54260 488
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42716 114
New

We're in Beta

About us Mission Statement