Q:

Scope records a user has purchased

This is my setup:

users have many purchases
packs have many purchases
packs have many recipes

I want to select all recipes a user has bought with a scope in the Recipe class. This is what I have as of now:
scope :purchased, lambda { |user| includes(pack: :purchases).where(packs: { purchases: { user: user } }) }

Because of some reason when I call Recipe.purchased(current_user) I get all Recipe records.
What am I doing wrong with the scope?

A:

This can be done easily in Rails. You just use has_many with the :through option like this: 
class User < ApplicationRecord
  has_many :purchases
  has_many :packs, through: :purchases
  has_many :recipes, through: :packs
end

user = User.first
user.recipes # returns all user's recipes

