So I'm struggling with what seems to be a common problem. I developed my rails app with SQLite and have now pushed it to Heroku (postgreSQL) and encountered this error:
GroupingError: ERROR: column "projects.id" must appear in the GROUP BY clause or be used in an aggregate function
as a result of my code:
@projects = @user.projects.select('MAX(id), *').group(:unique_id).all.paginate(page: params[:page])
where I pull all of a user's projects. unique_id identifies each project and I use MAX(id)as a way of pulling the most recent version of the project.
How can I change my code so that it works is both SQLite for development and postgreSQL for production? I've looked at several other questions that deal with this error but haven't found a great solution for what I'm doing. I'm inclined to use distinct instead of group but I'm not sure how. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire