Loading relationships from existing entity instance inside the same instance
See original GitHub issueIssue type:
[x] question [ ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem: It is possible to load relationships using an existing entity instance?
For example, I have an User
entity with OneToMany
relationship with the Reservation
entity. Then I have a user (user = User.find(1)
) and I want the reservations property inside the user instance object like so(with no eager loading, lazy loading or query builder):
let user = User.find(1);
// do some processing
return user;
/*
expect: {
id : 1,
email : 'some@email'
}
*/
// load reservations
user.load('reservations')
return user;
/*
expect: {
id : 1,
email : 'some@email',
reservations: [{etc},{etc},{etc}]
}
*/
PS. I cannot use eager loading because I will get circular error
. The only option I see is by using lazy loading
and adding the reservations
array in my user instance like so:
let user = User.find(1);
let reservations = await user.reservations // after setting lazy loading in my entity
user.reservations = reservations;
return user;
Issue Analytics
- State:
- Created 5 years ago
- Reactions:18
- Comments:12 (2 by maintainers)
This is funny. A few moments ago I found myself needing this feature and after a quick google I found out that I was the person who posted this issue on Github. lol
Maybe it needs to be added on a priority list or something? @pleerock
Any updates?