Skip to content

Commit

Permalink
production build: fixed getRepository call
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-lang committed Nov 30, 2017
1 parent a8a5b34 commit c722957
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ This project demonstrates how that would work.
### Limitations to TypeORM when using production builds
Since Ionic make a lot of optimizations when building for productions, the following limitations occur
1. Entities have to be marked with the table name (eg `@Entity('table_name')`)
2. `getRepository()` has to be called with the name of the entity instead of the class (eg `getRepository('post') as Repository<Post>`)
2. Date fields aren't supported
```ts
@Column()
Expand Down
3 changes: 2 additions & 1 deletion src/pages/home/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getRepository } from 'typeorm';
import { Author } from '../../entities/author';
import { Category } from '../../entities/category';
import { Post } from '../../entities/post';
import { Repository } from 'typeorm/repository/Repository';

@Component({
selector: 'page-home',
Expand Down Expand Up @@ -36,7 +37,7 @@ export class HomePage {
post.categories = [category1, category2];
post.author = author;

const postRepository = getRepository(Post);
const postRepository = getRepository('post') as Repository<Post>;
await postRepository.save(post);

console.log("Post has been saved");
Expand Down

0 comments on commit c722957

Please sign in to comment.