knox ревизій цього gist . До ревизії
1 file changed, 31 insertions
TypeORM-readme-46.ts(файл створено)
@@ -0,0 +1,31 @@ | |||
1 | + | import { AppDataSource } from "./index" | |
2 | + | ||
3 | + | // create a few albums | |
4 | + | const album1 = new Album() | |
5 | + | album1.name = "Bears" | |
6 | + | await AppDataSource.manager.save(album1) | |
7 | + | ||
8 | + | const album2 = new Album() | |
9 | + | album2.name = "Me" | |
10 | + | await AppDataSource.manager.save(album2) | |
11 | + | ||
12 | + | // create a few photos | |
13 | + | const photo = new Photo() | |
14 | + | photo.name = "Me and Bears" | |
15 | + | photo.description = "I am near polar bears" | |
16 | + | photo.filename = "photo-with-bears.jpg" | |
17 | + | photo.views = 1 | |
18 | + | photo.isPublished = true | |
19 | + | photo.albums = [album1, album2] | |
20 | + | await AppDataSource.manager.save(photo) | |
21 | + | ||
22 | + | // now our photo is saved and albums are attached to it | |
23 | + | // now lets load them: | |
24 | + | const loadedPhoto = await AppDataSource.getRepository(Photo).findOne({ | |
25 | + | where: { | |
26 | + | id: 1, | |
27 | + | }, | |
28 | + | relations: { | |
29 | + | albums: true, | |
30 | + | }, | |
31 | + | }) |
Новіше
Пізніше