One to many through join table relationship

Hi,
I am quite a newbie on Elixir, I come from rails. And keep trying how to figure out what is the best way for handling a one-to-many through a join table.

A user have many rooms. But not all users only user with the admin role. So there is

  • User table,
  • Room table
  • Admin the join table .
    schema “admin” do
    belongs_to :user, User
    belongs_to :room, Room
    end

What is the more idiomatic way to udpate the Admin for a given Room ?

I hope it is clear enought !

Are the official docs not good enough?

Hello and welcome,

It is not common to do one_to_many with a join table… usually it is done through a simple key on the belongs side.

I cannot recall where, but I think it is advised to do a many_to_many, even if it is a one to many relationship.

More idiomatic than what? How are you updating it now?

Why do you need a join table here? Why not just a admin_id on the room itself?