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

Unique constraint not created on embedded entity field #3142

Closed
Nargonath opened this issue Nov 21, 2018 · 1 comment · Fixed by #3824
Closed

Unique constraint not created on embedded entity field #3142

Nargonath opened this issue Nov 21, 2018 · 1 comment · Fixed by #3824

Comments

@Nargonath
Copy link

Issue type:

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

Database system/driver:

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

TypeORM version:

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

Steps to reproduce or a small repository showing the problem:

export class Contact {
  @Column({ unique: true })
  email: string;
}
import { Contact } from './contact';

@Entity()
export class Person extends BaseEntity {
  @PrimaryGeneratedColumn()
  id: number;

  @Column(_type => Contact)
  contact: Contact;

  // I added the unique: true just for the sake of the example
  @Column({ default: StatusChoices.PENDING, unique: true })
  status: StatusChoices;
}

No unique constraint is created for the embedded entity field thus I can create 2 persons with the same email. Here are 2 screenshots from phpPgAdmin showing that the unique is created for status but not for contact.email:
image
image

@Nargonath
Copy link
Author

Cool, thanks for the fix. 🎉

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

Successfully merging a pull request may close this issue.

4 participants