Using existing values in model definition functions #198
-
|
Hey folks, Been using the data library for a couple of things and it's going great. Just encountered an issue though - I have a model definition using user: {
id: primaryKey(faker.datatype.uuid),
firstName: faker.name.firstName,
lastName: faker.name.lastName,
email: faker.internet.exampleEmail
}This works fine, but I'd like the user's email to be generated with correct user: {
id: primaryKey(faker.datatype.uuid),
firstName: faker.name.firstName,
lastName: faker.name.lastName,
email: () => faker.internet.exampleEmail(??, ??)
}Could be my javascript needs polishing but not sure how I can get access to the existing |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Can see this question is up for discussion in this issue, so will follow that. |
Beta Was this translation helpful? Give feedback.
-
UpdateSince v1.0, Data no longer provides any object modeling capabilities. You can use any Standard Schema-compliant library (Zod, ArkType, etc) to describe a schema where some properties are derived from other properties. Here's an example of deriving the data/tests/create-derived-property.test.ts Lines 5 to 16 in 471a1f6 You should do this on the schema level. This means that you should consult your schema library of choice on the exact APIs to achieve such derived values. |
Beta Was this translation helpful? Give feedback.
Update
Since v1.0, Data no longer provides any object modeling capabilities. You can use any Standard Schema-compliant library (Zod, ArkType, etc) to describe a schema where some properties are derived from other properties.
Here's an example of deriving the
emailfield from thefirstsNameandlastNamefields:data/tests/create-derived-property.test.ts
Lines 5 to 16 in 471a1f6