knox 已修改 . 還原成這個修訂版本
1 file changed, 26 insertions
TypeORM-readme-38.ts(檔案已創建)
@@ -0,0 +1,26 @@ | |||
1 | + | import { AppDataSource } from "./index" | |
2 | + | ||
3 | + | // create photo object | |
4 | + | const photo = new Photo() | |
5 | + | photo.name = "Me and Bears" | |
6 | + | photo.description = "I am near polar bears" | |
7 | + | photo.filename = "photo-with-bears.jpg" | |
8 | + | photo.isPublished = true | |
9 | + | ||
10 | + | // create photo metadata object | |
11 | + | const metadata = new PhotoMetadata() | |
12 | + | metadata.height = 640 | |
13 | + | metadata.width = 480 | |
14 | + | metadata.compressed = true | |
15 | + | metadata.comment = "cybershoot" | |
16 | + | metadata.orientation = "portrait" | |
17 | + | ||
18 | + | photo.metadata = metadata // this way we connect them | |
19 | + | ||
20 | + | // get repository | |
21 | + | const photoRepository = AppDataSource.getRepository(Photo) | |
22 | + | ||
23 | + | // saving a photo also save the metadata | |
24 | + | await photoRepository.save(photo) | |
25 | + | ||
26 | + | console.log("Photo is saved, photo metadata is saved too.") |
上一頁
下一頁