Última actividad 1729146797

Revisión 1601985b5a30240e64406c4b4b83dfcb6dcea1f9

TypeORM-readme-46.ts Sin formato
1import { AppDataSource } from "./index"
2
3// create a few albums
4const album1 = new Album()
5album1.name = "Bears"
6await AppDataSource.manager.save(album1)
7
8const album2 = new Album()
9album2.name = "Me"
10await AppDataSource.manager.save(album2)
11
12// create a few photos
13const photo = new Photo()
14photo.name = "Me and Bears"
15photo.description = "I am near polar bears"
16photo.filename = "photo-with-bears.jpg"
17photo.views = 1
18photo.isPublished = true
19photo.albums = [album1, album2]
20await AppDataSource.manager.save(photo)
21
22// now our photo is saved and albums are attached to it
23// now lets load them:
24const loadedPhoto = await AppDataSource.getRepository(Photo).findOne({
25 where: {
26 id: 1,
27 },
28 relations: {
29 albums: true,
30 },
31})