Seed entity with lazy relations
Seed entity with lazy relations

given following model:

```typescript
@Entity(User.TABLE_NAME)
export class User {

    public static readonly TABLE_NAME = 'user';

    @PrimaryGeneratedColumn()
    public id: number;

    @Column({
        name: 'first_name',
        nullable: false,
    })
    public firstName: string;

    @Column({
        name: 'last_name',
        nullable: false,
    })
    public lastName: string;

    @Column({
        name: 'email',
        nullable: false,
        unique: true,
    })
    public email: string;

    @Column({
        name: 'password',
        nullable: false,
    })
    public password: string;

    @ManyToMany(type => Authority, authority => authority.users)
    @JoinTable({ name: 'user_authority' })
    public authorities: Promise<Authority[]>;
}
```

To create a new user entity you need to assign a promise to the entity, but to save you need to pass the authority object directly as mentioned here: https://github.com/typeorm/typeorm/issues/1180#issuecomment-346055615

```typescript
/**
 * User factory
 */
factory.define(User, (faker: typeof Faker, args: any[]) => {
    const gender = faker.random.number(1);
    const firstName = faker.name.firstName(gender);
    const lastName = faker.name.lastName(gender);
    const email = faker.internet.email(firstName, lastName);
    const authority = args[0] as Authority;

    const user = new User();
    user.firstName = firstName;
    user.lastName = lastName;
    user.email = email;
    user.password = env.admin.password;
    user.authorities = Promise.resolve([authority]);
    return user;
});
````
w3tecch/express-typescript-boilerplate,w3tecch/express-typescript-boilerplate,w3tecch/express-typescript-boilerplate