I want to display a gallery of magazines that shows the newest issue for each magazine title, but ordered by the number of subscriptions on that magazine. I came up with this query
class IssuesController < ApplicationController
def index
@issues = Issue
.includes(:magazine)
.order('magazines.subscriptions_count DESC')
.order(:release)
.paginate(page: @page, per_page: 25)
end
end
It correctly orders them by the suscriptions_count, however there are many entries for each magazine, each issue is displayed in order. I just want the first magazine for each one. I've tried adding uniq
to the query, group(:magazine_id)
, limit(1)
, and more but I can't get it to only display one issue per magazine title.