i have the following query which works
@engagements = Engagement.includes(:participation).where(influencer_authorization_id: current_influencer.id).group_by { |p| p.status }
i am trying to use the Database function instead of the Ruby/Rails function to group and the following is my code
engagements = Engagement.where(influencer_authorization_id: current_influencer.id).group("status")
But i am getting the following error
ERROR: column "engagements.id" must appear in the GROUP BY clause or be used in an aggregate function LINE 1: SELECT "engagements".* FROM "engagements" WHERE "engagements... ^
Update
I tried doing the following but still doesnt work
engagements = Engagement.select("engagements.*").where(influencer_authorization_id: current_influencer.id).group("engagement.status")
ERROR
ERROR: missing FROM-clause entry for table "engagement" LINE 1: ...ents"."influencer_authorization_id" = $1 GROUP BY engagement... ^