mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-01 03:46:44 +01:00
add roles and filter preload
This commit is contained in:
parent
040622574f
commit
8a4b6d3b0a
2 changed files with 11 additions and 0 deletions
|
@ -164,4 +164,13 @@ defmodule Philomena.Users do
|
|||
|> User.creation_changeset(params)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
@impl Pow.Ecto.Context
|
||||
def get_by(clauses) do
|
||||
User
|
||||
|> join(:left, [u], _ in assoc(u, :roles))
|
||||
|> join(:left, [u, _], _ in assoc(u, :current_filter))
|
||||
|> preload([_, r, cf], [current_filter: cf, roles: r])
|
||||
|> Repo.get_by(clauses)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,6 +22,7 @@ defmodule Philomena.Users.User do
|
|||
alias Philomena.Galleries.Gallery
|
||||
alias Philomena.Users.User
|
||||
alias Philomena.Commissions.Commission
|
||||
alias Philomena.Roles.Role
|
||||
|
||||
@derive {Phoenix.Param, key: :slug}
|
||||
|
||||
|
@ -34,6 +35,7 @@ defmodule Philomena.Users.User do
|
|||
has_many :unread_notifications, UnreadNotification
|
||||
has_many :notifications, through: [:unread_notifications, :notification]
|
||||
has_one :commission, Commission
|
||||
many_to_many :roles, Role, join_through: "users_roles"
|
||||
|
||||
belongs_to :current_filter, Filter
|
||||
belongs_to :deleted_by_user, User
|
||||
|
|
Loading…
Reference in a new issue