Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid n+1 queries #101

Open
lsarni opened this issue Oct 16, 2017 · 1 comment
Open

Avoid n+1 queries #101

lsarni opened this issue Oct 16, 2017 · 1 comment

Comments

@lsarni
Copy link

lsarni commented Oct 16, 2017

Is there a way to avoid n+1 queries?

I have a class Company:

class Company < ActiveRecord::Base
   acts_as_followable  
end

And I make a query to get a certain type of companies, but I want to get the followers of each one of those and I end up with n+1 queries:

SELECT COUNT(*) FROM "follows" WHERE "follows"."followable_id" = $1 AND "follows"."followable_type" = $2 AND "follows"."blocked" = $3 [["followable_id", 419], ["followable_type", "Company"], ["blocked", "f"]]

@RailsCod3rFuture
Copy link

Anyone created a fork with optimized queries for this issue yet??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants