Fixing SQL errors when trying to eagerload associations from empty results

fixes #3167 and #3113