forked from typeorm/typeorm
/
PhotoAlbumCategory.ts
36 lines (30 loc) · 1.06 KB
/
PhotoAlbumCategory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import {Connection} from "../../../../../src";
import {ViewColumn} from "../../../../../src/decorator/columns/ViewColumn";
import {ViewEntity} from "../../../../../src/decorator/entity-view/ViewEntity";
import {Album} from "./Album";
import {Category} from "./Category";
import {Photo} from "./Photo";
@ViewEntity({
expression: (connection: Connection) => connection.createQueryBuilder()
.select("photo.id", "id")
.addSelect("photo.name", "name")
.addSelect("photo.albumId", "albumId")
.addSelect("category.name", "categoryName")
.addSelect("album.name", "albumName")
.from(Photo, "photo")
.leftJoin(Album, "album", "album.id = photo.albumId")
.leftJoin(Category, "category", "category.id = album.categoryId")
.where(`category.name = 'Cars'`)
})
export class PhotoAlbumCategory {
@ViewColumn()
id: number;
@ViewColumn()
name: string;
@ViewColumn()
categoryName: string;
@ViewColumn()
albumName: string;
@ViewColumn({ name: "albumId" })
photoAlbumId: number;
}