I believe I may have found a solution. Would love some input if there is a better approach or maybe some flaws so what seems to be working. Thanks again
def get_tags(search) do
subquery =
from(pt in PostTag,
select: %{tag_id: pt.tag_id, postCount: count(pt.tag_id)},
group_by: pt.tag_id
)
query =
from(t in Tag,
join: pt in subquery(subquery),
on: t.id == pt.tag_id,
where: ilike(t.name, ^search),
select: %{id: t.id, name: t.name, count: pt.postCount}
)
# from(t in Tag, join: p in assoc(:posts), select: t.name)
Repo.all(query)
end


















