this problem is difficult to describe, but I"ll try to
,
orm(typeOrm),mock
ProjectPanorama(ProjectPanorama)
3Panorama(mockData.defaultPanoramas)
- 3Panorama3ProjectPanorama
ProjectPanorama
projectId | panoramaId |
---|---|
1 | 3 |
1 | 3 |
1 | 3 |
3panorama,
,let proj_pano
,const
the result becomes normal
< table > < thead > < tr > < th > projectId < / th > < th > panoramaId < / th > < / tr > < / thead > < tbody > < tr > < td > 1 < / td > < td > 1 < / td > < / tr > < tr > < td > 1 < / td > < td > 2 < / td > < / tr > < tr > < td > 1 < / td > < td > 3 < / td > < / tr > < / tbody > < / table >it is because of this phenomenon that I suspect that the problem is async, not the orm library
< hr >possible reasons
due to the first await in forEac
panoramas.forEach(async (p, j) => {
proj_pano = new ProjectPanorama()
proj_pano.project = project
proj_pano.panorama = p
// marker
const markerToPP = []
for (let k = 1; k <= 3; k += 1) {
await marker.save() // await
}
proj_pano.markers = markerToPP
await proj_pano.save()
// project.projectPanoramas.push(proj_pano)
})
causes the program to execute like this
proj_pano = new ProjectPanorama()
proj_pano.project = project
proj_pano.panorama = p
const markerToPP = []
// await,forEach
// .....
proj_pano = new ProjectPanorama() // proj_pano
proj_pano.project = project
proj_pano.panorama = p
const markerToPP = []
// ....
// await
// proj_pano,proj_pano
proj_pano.markers = markerToPP // markerToPP,
await proj_pano.save() //ormsave,savemarkers,
//proj_pano
proj_pano.markers = markerToPP //
await proj_pano.save()
//proj_pano
proj_pano.markers = markerToPP //
await proj_pano.save()
also do not use await
https://stackoverflow.com/que.