-
Notifications
You must be signed in to change notification settings - Fork 88
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
Duplicating assigned attributes #72
Comments
Hi @jonatanklosko, Factory.define('user', User, {
username: Factory.sequence(n => `sherlock_${n}`),
name: 'Sherlock Holmes',
password: 'password',
passwordConfirmation: null,
}, {
afterBuild: model => {
model.passwordConfirmation = model.password;
return model;
},
}); Just to add some details, the problem with having it the way you suggested is how to ensure that You can use the Let us know in case you face any issues. |
Hey @chetanism, afterBuild: model => {
model.passwordConfirmation = model.passwordConfirmation || model.password;
return model;
}, The problem with this solution is that I can think of a feature, that would allow us to do: /* ... */
password: "secret",
passwordConfirmation: factory.duplicate('password')
/* ... */
/* Or even more flexible */
/* ... */
password: "secret",
passwordConfirmation: factory.after('password', password => /* do something and return */)
/* ... */ This way you can evaluate all normal attributes and those |
@chetanism I think maybe we should consider calling both |
@jonatanklosko, sorry for a long delay! |
Yeah this behavior makes more sense. The PR looks great, thanks! =) |
#73 has been merged, closing this issue now. Please advise if there's any issues. |
I've just realised that it's not invoked after |
Hi @jonatanklosko, the order of execution for these methods is |
Consider the following factory:
I'd expect the following to pass.
The syntax could differ but I think it's common use case to duplicate (or do something else) on an already assigned attribute.
The text was updated successfully, but these errors were encountered: