question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Id of entity with UUID type instead of Number not working

See original GitHub issue

When I define my model in TypeORM as:

@Entity()
export class User {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ default: false })
  isActivated: boolean;
}

I can use POST without any problem. However when I use PATCH it is expecting the id to be a numeric string:

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "Validation failed. Param 'id': numeric string is expected"
}

The body I’ve sent is:

{
    "id": "6aca65b8-ac87-4db8-a492-f4461655b5fa",
    "isActivated": true
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

19reactions
mehmet-erimcommented, Dec 30, 2019

New version configuration is like this:

@Crud({
  model: {
    type: YourEntity,
  },
  params: {
    id: {
      type: 'uuid',
      primary: true,
      field: 'id',
    },
  },
})
7reactions
michaelyalicommented, Apr 2, 2019

so in your case, you should add this to the CrudOptions:

{
  params: {
    id: 'uuid'
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to generate UUID id for my entities - Stack Overflow
For ID field I used Postgres uuid type and I set as default value uuid_generate_v4() . All works correctly when I generate a...
Read more >
How to generate UUIDs as primary keys with Hibernate
If you decide to use UUIDs as primary keys, Hibernate can generate them based on IETF RFC ... But that doesn't mean that...
Read more >
The Ultimate Guide on Client-Generated IDs in JPA Entities
Conclusion: UUID is a good choice for surrogate IDs if we don't want or cannot use a database for ID generation. It is...
Read more >
Hibernate and UUID identifiers - Vlad Mihalcea
Learn how the UUID entity attributes are persisted when using JPA and Hibernate for both assigned and auto-generated identifiers.
Read more >
How to use String UUID in Hibernate with MySQL | Codementor
Using a unique ID for columns in a table is important. Besides the auto-increment option, we can use the Java UUID column, however, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found