Fixed active record nil_relation detection error