Update Public.get_autor! to only display public Artikel
Also get rid of the superfluous additional loop over articles/translations.
This commit is contained in:
@ -67,7 +67,28 @@ implement to_param protocol (no more needed for Outlook.Translations.Translation
|
||||
end
|
||||
|
||||
def get_autor!(id) do
|
||||
Repo.get!(Author, id)
|
||||
|> Repo.preload([articles: [:translations]])
|
||||
q = from au in Author,
|
||||
select: %Autor{
|
||||
name: au.name,
|
||||
description: au.description,
|
||||
homepage_name: au.homepage_name,
|
||||
homepage_url: au.homepage_url,
|
||||
},
|
||||
where: au.id == ^id
|
||||
autor = Repo.one(q)
|
||||
|
||||
q2 = from a in Article,
|
||||
join: t in Translation, on: t.article_id == a.id,
|
||||
select: %Artikel{
|
||||
title: t.title,
|
||||
date: t.date,
|
||||
teaser: t.teaser,
|
||||
id: t.id,
|
||||
date_org: a.date
|
||||
},
|
||||
where: a.author_id == ^id and t.public == true
|
||||
artikel = Repo.all(q2)
|
||||
|
||||
%Autor{autor | artikel: artikel}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user