forked from petejkim/factory-lady
-
Notifications
You must be signed in to change notification settings - Fork 86
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
many factory.assoc with same parent #123
Comments
Here's a solution I've used |
My solution: factory.define(
'FtpUser',
models.FtpUser,
{
accountId: factory.assoc('Account', 'id'),
},
{
afterBuild: async model => {
const account = await models.Account.query().findById(model.accountId)
if (!model.name) {
model.name = account.email
}
return model
},
}
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Helly Simon. Congrats on the lib. I've been using it since 2016.
Today I migrated to the 4.3.0 version as I am creating new tests in my application.
Right now I have the following models:
In my test, I try to create all the models but, since they all are associated with testUser2, then it gets an error for unique fields (since it tries to recreate it 4 times).
So my questions are:
The text was updated successfully, but these errors were encountered: