hawkyre
Add field in ecto schema that refers to a single instance of a many-to-many relationship
I have a user that has many scopes, and a scope can be had by many users. This relationship has a join table named user_scope However, users also have a current_scope, which mandates some functionality that they can do. This current scope is mapped with a foreign key current_scope_id which points to the user_scope table, not to the scope table. I want to have a field in my users schema that maps the current_scope_id directly to the scope table, similar to how the many_to_many method has a :through option to make many-to-many relationships accessible without having to perform any extra steps.
Is there any easy way to do this that doesn’t involve having to manually load the course?
Marked As Solved
moogle19
The has_one/3 macro also has the option to pass a :through key (Ecto.Schema — Ecto v3.14.0).
That would probably work for your problem.
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
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









