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

fix: stop factory creating unused initial association #36

Merged

Conversation

dkpoult
Copy link

@dkpoult dkpoult commented Jul 29, 2024

  • Modifies the resolveAssociations function of the Factory class so that it first merges any provided overrides before looping through the attributes to resolve the associations - which now avoids an unexpected entry in the database when the factory resolves a model with an association for the first time.
  • Adds a new test case to ensure an additional model isn't saved by the adapter.

Copy link
Owner

@thiagomini thiagomini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one small change here, I can approve and merge it as soon as we have it fixed - thank you for the contribution anyway!

@@ -488,6 +490,58 @@ describe('Factory', () => {
expect(address).toMatchObject(addressAttributes);
expect(address.userId).toBe(userAttributes.id);
});

it('it should not create overridden associations', async () => {
Copy link
Owner

@thiagomini thiagomini Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is something that is not exclusive to Sequelize, so it'd be better to test it with the Object Adapter (which is more database-agnostic). If you want to double check this is not creating a new entry in the database when used with Sequelize, I advise also adding a test to the sequelize-specific test suite

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thiagomini sorry I didn't notice this for a while - I've changed it to ObjectAdapter 👍 doesn't seem like the issue was specific to sequelize so no need to put it into a specific test suite I think

@dkpoult
Copy link
Author

dkpoult commented Aug 14, 2024

@thiagomini just checking if there's anything left to do here or if this can get merged in?

@thiagomini
Copy link
Owner

This can be merged @dkpoult , I'll create a release soon

@thiagomini thiagomini merged commit 525a883 into thiagomini:main Aug 14, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants