Vanilla JavaScript Lazy Loading Relations
See original GitHub issueIssue type:
[ ] question [ x ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ x ] 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:
I am using TypeORM with vanilla JavaScript and I have a one-to-many relation on a model (let’s call it model1) and its inverse many-to-one relation on another model (let’s call it model2). I have set up the Model2Schema to the default eager load and Model1Schema to lazy load the relation (since I don’t want to always load the “many” part each time I get this model). However I always get the model1.model2s to be empty. My code looks like this:
Model1.findOne({}).then(async model1 => { console.log(model1); let model2s = await model1.model2s; console.log(model2s); }).catch(error);
The model2s
variable is undefined
.
P.S. I had to define the then
callback as async
since await
has to work with async
functions.
Any help?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
We are planning to add JavaScript docs in next 0.3.0 version.
The problem was that I did not specify the inverseSide of the relation. I came to that conclusion with a lot of tinkering and looking through a lot of the typeorm code though. It would be really helpful if there is a bit more documentation for Vanilla Javascript. 😄