summaryrefslogtreecommitdiff
path: root/lib/aggiedit
diff options
context:
space:
mode:
authorLogan Hunt <loganhunt@simponic.xyz>2022-04-06 14:16:29 -0600
committerLogan Hunt <loganhunt@simponic.xyz>2022-04-06 14:16:29 -0600
commit5ad6bbfce753e048a4f866ad6324f4b4d6f16618 (patch)
tree7b46f4d659ff32ee475b3a9176eb987ca3969c34 /lib/aggiedit
parent4067339e8cf9dbd624a8fa0183d7a29c73b2e762 (diff)
downloadaggiedit-5ad6bbfce753e048a4f866ad6324f4b4d6f16618.tar.gz
aggiedit-5ad6bbfce753e048a4f866ad6324f4b4d6f16618.zip
Update associations
Diffstat (limited to 'lib/aggiedit')
-rw-r--r--lib/aggiedit/accounts/user.ex1
-rw-r--r--lib/aggiedit/rooms/post.ex22
-rw-r--r--lib/aggiedit/rooms/room.ex1
3 files changed, 21 insertions, 3 deletions
diff --git a/lib/aggiedit/accounts/user.ex b/lib/aggiedit/accounts/user.ex
index aeb37ed..65c2463 100644
--- a/lib/aggiedit/accounts/user.ex
+++ b/lib/aggiedit/accounts/user.ex
@@ -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
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
diff --git a/lib/aggiedit/rooms/room.ex b/lib/aggiedit/rooms/room.ex
index 24f1b8a..2a23555 100644
--- a/lib/aggiedit/rooms/room.ex
+++ b/lib/aggiedit/rooms/room.ex
@@ -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