hawkyre

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

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.

Last Post!

hawkyre

hawkyre

Yup it does, thank you :smiley:

Where Next?

Popular in Questions Top

JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement