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
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
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?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex









