Skip to content

Commit c722957

Browse files
committed
production build: fixed getRepository call
1 parent a8a5b34 commit c722957

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ This project demonstrates how that would work.
1919
### Limitations to TypeORM when using production builds
2020
Since Ionic make a lot of optimizations when building for productions, the following limitations occur
2121
1. Entities have to be marked with the table name (eg `@Entity('table_name')`)
22+
2. `getRepository()` has to be called with the name of the entity instead of the class (eg `getRepository('post') as Repository<Post>`)
2223
2. Date fields aren't supported
2324
```ts
2425
@Column()

src/pages/home/home.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getRepository } from 'typeorm';
55
import { Author } from '../../entities/author';
66
import { Category } from '../../entities/category';
77
import { Post } from '../../entities/post';
8+
import { Repository } from 'typeorm/repository/Repository';
89

910
@Component({
1011
selector: 'page-home',
@@ -36,7 +37,7 @@ export class HomePage {
3637
post.categories = [category1, category2];
3738
post.author = author;
3839

39-
const postRepository = getRepository(Post);
40+
const postRepository = getRepository('post') as Repository<Post>;
4041
await postRepository.save(post);
4142

4243
console.log("Post has been saved");

0 commit comments

Comments
 (0)