findOne
- where 조건만 단순히 전달할 때 사용 (ID값이나 조건 객체를 모두 받아 혼동 가능)
- 관계로드(relation), select, order같은 옵션 못 씀
const user = await userRepository.findOne(1);
const user = await userRepository.findOne({ name: "John" });
findOneBy
- where외에도 relation/select/order등 다양한 옵션 설정 가능
- 응답 모양 제어가 필요할땐 findOne이 더 유리
const user = await userRepository.findOneBy({ id: 1 });
const user = await userRepository.findOneBy({ name: "John" });
예시
const user = await userRepository.findOne({
where: { name: "John" },
relations: ["posts"],
order: { createdAt: "DESC" }
});
const user = await userRepository.findOneBy({ name: "John" });