i have two rows in database
[
Anime {
id: 1,
title: 'Kimi ',
synopsis: 'Perangn berakhir?',
metaDescription: 'Kuma Ku online',
coverLink: 'https://res.cloudinary.com/antaraksi/image/upload/v1607682688/1VtaTXsHTRfh8m49OVJfMb4JVuh_e0hy3g.jpg',
slug: 'kimi-to-boku-no-saigo-no-senjou-aruiwa-sekai-ga-hajimaru-seisen',
view: 8,
episodes: []
},
Anime {
id: 2,
title: 'Hajimaru Seisen1',
synopsis: 'berakhir?1',
metaDescription: 'Kuma Kuma Kuma Ba Kuma Bear free, Kuma Kuma Kuma Bear online1',
coverLink: 'https://res.cloudinary.com/antaraksi/image/upload/v1607682688/1VtaTXsHTRfh8m49OVJfMb4JVuh_e0hy3g.jpg',
slug: 'kimi-to-boku-no-saigo-no-senjou-aruiwa-sekai-ga-hajimaru-seisen-1',
view: 2,
episodes: []
}
]
i want to find one by the slug.
async findOne(slug: string) {
const findOptions = {
slug,
relations: ['episodes']
}
const anime = await this.animesRepository.find(findOptions);
console.log(anime);
return anime;
}
but it always return two rows. the slug column is text
in the database. how can i find one by the slug?
You need to use the method findOone
to get one row, you can do something like:
const user = await this.animesRepository.findOne({
relations: ['episodes'],
where: slug
});