False positive with count associtiaons
CarlosUvaSilva opened this issue · comments
Carlos Silva commented
I have this inside a controller
users = User.includes(
:posts,
)
and this inside the User model
def number_of_posts
if posts.loaded?
posts.size
else
posts.count
end
end
If I include posts I get the expected:
SELECT "posts".* FROM "posts" WHERE "posts"."user_id" IN ($1, $2, $3, $4, $5)
and if I don't include I get one of these for each user:
SELECT COUNT(*) FROM "posts" WHERE "posts"."user_id" = $1
Problem is Bullet is telling me to NOT include the posts
AVOID eager loading detected
User => [:posts]
Remove from your query: .includes([:posts])
Thank you!
Shiva Bhusal commented
I am also seeing massive false positives during upgrading Rails 6 to 7(bullet 7).
Toeknee commented
Same here
Richard Huang commented
I think it supposed to be fixed in bullet 7.1.3