Answer the question
In order to leave comments, you need to log in
How to optimize following query in Active Record?
there is the following code:
category = Category.where(slug: params[:category]).first
result = Slide.where(category_id: category.id)
SELECT *
FROM
slides AS sl
INNER JOIN
categories AS ct
ON
sl.category_id = ct.id
WHERE ct.slug = 'home-work';
SELECT *
FROM slides
WHERE category_id IN (SELECT id FROM categories WHERE slug = 'home-work');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question