I am trying to get records of each category limited to 5, but I ended up returning only 5 records.
How can I translate this sql statement in Rails ActiveRecord?
SELECT *
FROM "jobs" a
WHERE (
SELECT COUNT(*)
FROM jobs
WHERE ID = a.ID
) <= 5
AND jobkey_confirmation IS NOT NULL
AND EXTRACT(MONTH from created_at) = EXTRACT(MONTH from now())
I was just able to do the following, which returned only 5 records as mentioned above:
scope :confirmed_this_month, where("jobkey_confirmation IS NOT NULL AND EXTRACT(MONTH from created_at) = EXTRACT(MONTH from now())").group("category").limit(5).order("created_at DESC")