Skip to content

Instantly share code, notes, and snippets.

@AndrewVos
Created December 4, 2014 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewVos/4c9bd2bd4166f03c237d to your computer and use it in GitHub Desktop.
Save AndrewVos/4c9bd2bd4166f03c237d to your computer and use it in GitHub Desktop.
activities = Activity.includes(:product)
.order("product_id, created_at DESC")
.select("DISTINCT ON (product_id) activities.*")
.page(page).per(second_page_size).map do |activity|
activity.product.activity = activity
activity.product
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment