Well the issue is that the explorer always lets me write the uuid and when I put it generated: true it does not let me put the default: () => uuid ()
import {Entity, model, property} from '@loopback/repository';
import {v4 as uuid} from 'uuid'
@model({
name: 'users',
settings: {
hiddenProperties: ['password']
}
})
export class User extends Entity {
@property({
type: 'string',
id: true,
generated: true,
default: () => uuid(),
})
uuid: string;
@property({
type: 'string',
required: true,
})
email: string;
@property({
type: 'string',
required: true,
})
password: string;
constructor(data?: Partial<User>) {
super(data);
}
}
export interface UserRelations {
// describe navigational properties here
}
export type UserWithRelations = User & UserRelations;
There is some solution or you can implement a generated: () => uuid ()?
The 'generated: true' is to tell the database to generate the ID. You seem to be attempting to supply the value here via uuid but I'm not sure that is recommended as the database would be a better candidate to handle id generation. If you're going to be supplying a value via uuid, remove 'generated: true' as a good first step.
See ref: https://loopback.io/doc/en/lb3/Model-definition-JSON-file.html#id-properties
Perhaps someone else can give you better advice.
some databases do not accept uuid ... if I remove the generated if someone enters the field uuid this will not be written with a uuid
@frbuceta I am not sure I get your point entirely, but I will try to explain what I think would work for you.
This seems like a good approach
@property({
type: 'string',
id: true,
default: () => uuid(),
})
uuid: string;`
And just like @dougal83 said, I guess you can have it this way as well. Check this out for various Data Mapping Properties. So by this, you can have uuid as string in loopback, but map it to uuid property in say Postgres and the id generation would be handled by database itself.
@property({
type: 'string',
id: true,
generated: true,
postgresql: {
dataType: 'uuid'
},
})
uuid: string;
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository. This issue will be closed within 30 days of being stale.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.