Update associations
This commit is contained in:
parent
4067339e8c
commit
5ad6bbfce7
@ -13,6 +13,7 @@ defmodule Aggiedit.Accounts.User do
|
||||
field :role, Ecto.Enum, values: [:user, :admin], default: :user
|
||||
|
||||
belongs_to :room, Room, on_replace: :update
|
||||
has_many :posts, Aggiedit.Rooms.Post
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
@ -5,9 +5,10 @@ defmodule Aggiedit.Rooms.Post do
|
||||
schema "posts" do
|
||||
field :body, :string
|
||||
field :title, :string
|
||||
field :user_id, :id
|
||||
field :upload_id, :id
|
||||
field :room_id, :id
|
||||
|
||||
belongs_to :room, Aggiedit.Rooms.Room
|
||||
belongs_to :user, Aggiedit.Accounts.User
|
||||
belongs_to :upload, Aggiedit.Uploads.Upload
|
||||
|
||||
timestamps()
|
||||
end
|
||||
@ -18,4 +19,19 @@ defmodule Aggiedit.Rooms.Post do
|
||||
|> cast(attrs, [:title, :body])
|
||||
|> validate_required([:title, :body])
|
||||
end
|
||||
|
||||
def change_user(post, user) do
|
||||
change(post)
|
||||
|> put_assoc(:user, user)
|
||||
end
|
||||
|
||||
def change_upload(post, upload) do
|
||||
change(post)
|
||||
|> put_assoc(:upload, upload)
|
||||
end
|
||||
|
||||
def change_room(post, room) do
|
||||
change(post)
|
||||
|> put_assoc(:room, room)
|
||||
end
|
||||
end
|
||||
|
@ -6,6 +6,7 @@ defmodule Aggiedit.Rooms.Room do
|
||||
field :domain, :string
|
||||
|
||||
has_many :users, Aggiedit.Accounts.User
|
||||
has_many :posts, Aggiedit.Rooms.Post
|
||||
|
||||
timestamps()
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user