Small mismatch documentation & actual return type Uid #210
Replies: 2 comments 10 replies
-
True. Thanks for pointing it out. i switched to You could for example define a custom cast where you can have whatever uuid libary you want. I even think about removing Let me know what you think about the last idea....but as more i think about it, its defently better to do it that way. So at the end i have import UuidCast from './casts/UuidCast'
import { Model } from 'pinia-orm'
import { Str, Cast } from 'pinia-orm/decorators'
export class User extends Model {
@Cast(() => UuidCast)
@Str('') declare id: string
} You can even define a own decorator where you make both together and then having something like import type { CastAttribute, PropertyDecorator, TypeOptions } from 'pinia-orm'
import UuidCast from './casts/UuidCast'
/**
* Create a cast & str for an custom Uuid
*/
export function Uuidv4( value: string | null, options: TypeOptions = {} ): PropertyDecorator {
return (target, propertyKey) => {
const self = target.$self()
self.setCast(propertyKey, UuidCast)
self.setRegistry(propertyKey, () => {
const attr = self.string(value)
if (options.nullable)
attr.nullable()
return attr
})
}
} |
Beta Was this translation helpful? Give feedback.
-
@CodeDredd , thanks. I am nearly there creating uuidV4 keys though I need a last tip:
Scenario 1: @ repo.save({name:'hello', parentGroupId: null}) I get Scenario 2: change Question: how could I fix my code s.t. I can create a new model 'object'/instance/row with repo.save({name:'hello', parentGroupId:null}) that has a uuidV4() id (object key and value)? thanks! |
Beta Was this translation helpful? Give feedback.
-
Dear,
When I create a new model entry using useRepo(someRepo).make() it returns {id: somenanoId, otherparms } while the documentation says it will return a uuid. This causes a problem due to a postgresDb existing table type mismatch.
Questions:
thanks!
Beta Was this translation helpful? Give feedback.
All reactions