summaryrefslogtreecommitdiff
path: root/lib/aggiedit/rooms/post.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/aggiedit/rooms/post.ex')
-rw-r--r--lib/aggiedit/rooms/post.ex22
1 files changed, 19 insertions, 3 deletions
diff --git a/lib/aggiedit/rooms/post.ex b/lib/aggiedit/rooms/post.ex
index c6ca24a..ee9450d 100644
--- a/lib/aggiedit/rooms/post.ex
+++ b/lib/aggiedit/rooms/post.ex
@@ -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