Remove joined_rooms table

This commit is contained in:
Pim Kunis 2021-09-08 14:22:40 +02:00
parent 46b4199618
commit b12872fe2c
5 changed files with 23 additions and 74 deletions

View file

@ -3,7 +3,7 @@ defmodule Architex.Account do
import Ecto.{Changeset, Query}
alias Architex.{Repo, Account, Device, Room, JoinedRoom}
alias Architex.{Repo, Account, Device, Room, Membership}
alias ArchitexWeb.Client.Request.{Register, Login}
alias Ecto.{Multi, Changeset}
@ -19,8 +19,19 @@ defmodule Architex.Account do
has_many :devices, Device
many_to_many :joined_rooms, Room,
join_through: JoinedRoom,
join_keys: [account_id: :id, room_id: :id]
join_through: Membership,
join_keys: [account_id: :id, room_id: :id],
join_where: [membership: "join"]
many_to_many :invited_rooms, Room,
join_through: Membership,
join_keys: [account_id: :id, room_id: :id],
join_where: [membership: "invite"]
many_to_many :left_rooms, Room,
join_through: Membership,
join_keys: [account_id: :id, room_id: :id],
join_where: [membership: "leave"]
timestamps(updated_at: false)
end

View file

@ -1,17 +0,0 @@
defmodule Architex.JoinedRoom do
use Ecto.Schema
alias Architex.{Account, Room}
@type t :: %__MODULE__{
account_id: integer(),
room_id: String.t()
}
@primary_key false
schema "joined_rooms" do
belongs_to :account, Account, primary_key: true
belongs_to :room, Room, primary_key: true, type: :string
end
end