Relationship between `UserRepository` and `TypeormRepositoryBase`
See original GitHub issueWhile working through your database implementation, I was wondering why UserRepository
does not use TypeormRepositoryBase.findOne
?
Shouldn’t we do this instead:
const emailVO = new Email(email);
const user = await this.findOne({ email: emailVO });
return user;
And a second question: It seems like UserRepository.prepareQuery
removes all query parameters except for id
? Why?
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Custom repositories - typeorm - GitBook
You can create a custom repository which should contain methods to work with your database. For example, let's say we want to have...
Read more >Typeorm: what is the difference between entity.find() and ...
The Entity is actually the repository of a resource i.e the interface that interacts with the Database and gives you methods to perform ......
Read more >TypeORM - Working with Repository - Tutorialspoint
Repository is specific to an entity. In other words, each entity will have its own, build-in repository and it can be accessed using...
Read more >How can I extend Repository in a generic way? #2097 - GitHub
I want to exend base repository class to have a method named saveAndReturn() which first calls a save() and the returns findOneById() to...
Read more >TypeORM - Amazing ORM for TypeScript and JavaScript (ES7 ...
You work with entities everywhere in TypeORM. You can load/insert/update/remove and perform other operations with them.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s right, you have to adjust either a type to accept only the parameters specified in
prepareQuery
, or modify Repository to your liking. I’ll think how to improve it in the future so it’s less confusing.Ah, I see! Now I understand why one would want a more flexible way of preparing queries.
My worry, however, is that this implementation suggests a generality that is not there. The repository exposes a method
where
To anyone who has not studied
prepareQuery
in detail, this looks like a method that allows one to search the repository using arbitrary combinations of entity properties.But when I call, say,
UserRepository.findOne({ country: 'Germany' })
then the country param will be silently deleted and the result will be the same as if I had calledUserRepository.findOne({ })
. That could lead to nasty bugs.My “solution” was to remove the
find...
methods (except forfindById
, which works the same for every entity) fromTypeormRepositoryBase
and resort to custom implementations in each repository, in the spirit ofUserRepository.findOneByCountry(country: string)
.