It is a similar solution to your other question
permissions =
Enum.map(project_permissions, fn %{id: id, access_level: access_level} ->
{access_level, id} |> IO.inspect()
end)
Enum.any?(permissions, fn {permission, _id} -> permission == "Owner" end)
# or
Enum.find(permissions, fn {permission, _id} -> permission == "Owner" end)
A more direct way to find the full ProjectPermission
struct in one pass:
Enum.find(project_permissions, fn %{access_level: access_level} -> access_level == "Owner" end)
or instead of pulling a list of all records from the database and finding the one you want, you can more efficiently query the one record you want directly from the database
def get_project_permission_by_access_level(access_level) do
Repo.get_by(ProjectPermission, access_level: access_level)
end
get_project_permission_by_access_level("Owner")