Hey guys! I got this query:
q =
from p in Photo,
preload: [:model, :category],
full_join: f in Favorite,
on: f.photo_id == p.id,
group_by: p.id,
select_merge: %{
like_count: count(f.id),
liked_by_me: f.user_id == ^user.id
}
It’s working when I remove the line liked_by_me: f.user_id == ^user.id
, but I need the liked_by_me property to know whether a photo was liked by the current user or not. Another I could do it would be to map over the result and dynamically add the key, but I want to do it using Ecto. The error it’s throwing right now is ** (Postgrex.Error) ERROR 42803 (grouping_error) column "f1.user_id" must appear in the GROUP BY clause or be used in an aggregate function
. liked_by_me
should be a boolean as defined the schema.
Any help with this? Thanks!