Open loxy opened 21 hours ago
Hi @loxy, great to hear it's useful for you!
Unfortunately, there is just one way to achieve that safely - by overriding create
method. Unfortunately, create
is overloaded, this requires a bit of type gymnastics. Please refer to implementation of Factory#create
method to see the type overload.
Using pseudo-code, it would be something like this:
export class BasicClubFragmentFactory extends Factory<BasicClubFragment> {
define = {
clubId: () => faker.string.uuid(),
nodeId: "",
};
create(...args) {
const result = super().create(...args); // result is either BasicClubFragment or Array<BasicClubFragment>
// modify result to override `nodeId` with value of `clubId` and return result
}
}
I definitely recognize it as missing feature of the library. I am happy to provide a fully-fledged support for that without any hacks or overrides in the future. Although, I can't guarantee any time frame when it's available.
Let me know if any questions!
Hi!
I like you library! But I have one problem: I want to reuse the value from another field of the generated entity, like here:
nodeId
should depend onclubId
(for example making it base64 encoded). Or even easier using the same (random) data.I tried something like:
But that cannot work with current implementation.
Any ideas how to mitigate that? Maybe it would be cool if the field creator function would optionally accept the instance itself, like
nodeId: (instance: BasicClubFragment) => instance.clubId
Best regards, Kersten