Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mongo embedded document @BeforeInsert error when embedded document is not set #3450

Closed
ricardovf opened this issue Jan 18, 2019 · 4 comments
Closed

Comments

@ricardovf
Copy link

ricardovf commented Jan 18, 2019

Issue type:

[x] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[x] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] 0.2.11 (or put your version here)

Steps to reproduce or a small repository showing the problem:

user.ts
@Entity()
export class User {
    @Column()
    name: string;

    @Column(type => Phone)
   phone: Phone;
}
phone.ts
export class Phone {
  @Column()
  number: string;

  @BeforeInsert()
  beforePhoneCreate() {
    this.number = onlyNumbers(this.number);
  }
}
const user = new User();
user.name = 'Whatever'
await repo.save(user);

Save throws error that can't call beforePhoneCreate of undefined. As the Phone embedded document is optional an not defined. Can't i defined optional embedded document?

(i will keep reporting bugs as this lib is really great, but mongo support can improve)

@pleerock
Copy link
Member

Please feel free not only to report bugs, but also try to contribute and fix them. Mongo support can be improved A LOT, and we expect it to be a community initiative.

@ricardovf
Copy link
Author

ricardovf commented Jan 18, 2019

Please feel free not only to report bugs, but also try to contribute and fix them. Mongo support can be improved A LOT, and we expect it to be a community initiative.

I really want to, but now im programming 10-12h a day on my new company. When we succeed i intent to sponsor the main projects that are supporting our code, as TypeORM

@vlapo
Copy link
Contributor

vlapo commented Jan 18, 2019

@rustamwin do you want to check this?

@rustamwin
Copy link
Contributor

@vlapo Yeah, I'll check and try to fix it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants