class User; has_many :leave_credits
User.where(:id => [1,2]).joins(:leave_credits).count
# SELECT COUNT(*) FROM `users` INNER JOIN `leave_credits` ON `leave_credits`.`user_id` = `users`.`id` WHERE `users`.`id` IN (1, 2)
# may lead to 1+n problem
User.where(:id => [1,2]).includes(:leave_credits).count
# SELECT COUNT(*) FROM `users` WHERE `users`.`id` IN (1,2)
# will not query projects until you call user.leave_credits
# avoids 1+n problem