Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to allow "transient" values? #85

Open
mikesnare opened this issue Mar 22, 2024 · 1 comment
Open

Possible to allow "transient" values? #85

mikesnare opened this issue Mar 22, 2024 · 1 comment

Comments

@mikesnare
Copy link

FactoryBot for ruby has the notion of transient attributes that are used by the factory but not added to the model. How would one achieve that with factory.ts?

I have some factories that have a complex-ish string that is based on a simple ID but that ID is not part of the model. I don't want factory clients to have to know how to construct the string. I'd like them to be able to call the factory, passing in the id and any other attributes they want to use, and have the factory be able to construct the string out of the ID.

Is this possible in factory.js?

@willryan
Copy link
Owner

willryan commented Mar 26, 2024

Hi Mike,

This is not currently a feature in factory.ts, but I don't think it'd be super hard to implement. I don't have the time right now, but I will add it to the list for the next time I sit down to bang out some updates. That said, if I receive a PR I will make reviewing it a top priority. :)

Alternatively, depending on your use case, you could expose functions that call build() on your factories, rather than exposing the factories directly. In which case you can wrap factory.build() in a function that looks like (t: RecPartial<T>) => Omit<T,'id'>.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants