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: an entity with relations can be created also without them #79

Merged
merged 3 commits into from
Apr 23, 2021

Conversation

marcosvega91
Copy link
Member

@marcosvega91 marcosvega91 commented Apr 21, 2021

If an entity has some relations as for model definition but it is created without them, the creation was throwing an error because it was trying to attach relations anyway.

I have created a new test file but the name is not really good I think

Changes

  • It's now possible to create an entity without providing its relational properties (previously that would throw).

import { random } from 'faker'
import { factory, primaryKey, oneOf } from '@mswjs/data'

it('should not throw error if an entity with relation is created without it', () => {
Copy link
Member

Choose a reason for hiding this comment

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

I think this case should be added to all relevant test/relations/*.test.ts files, because the way oneOf and manyOf relations are handled may differ. Think of it as a spec point in each relationship kind support, not a standalone behavior.

Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

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

This looks great, just need to structure the tests (add necessary test cases to the existing relationship tests).

@marcosvega91
Copy link
Member Author

I had moved the test in their relation files but you made the same my mistake of the other day haahahaha, my last commit is dropped hahahah. I'll add it again, then I'll add some tests for missing properties.

@kettanaito
Copy link
Member

@marcosvega91, I don't think I dropped anything... When I pushed to the feature branch its remote got 1 commit. This likely means that you committed something locally but haven't pushed yet. Meanwhile, I've pushed changes to the remote that you didn't have locally. When pulling, you probably gave priority to the remote changes, so your uncommitted local ones got discarded.

What I usually do is git pull --rebase which tells me if I'm behind and ahead of the remote at the same time. This means I have new stuff but I also don't have some stuff from the remote. Then, depending on how many local commits I have, I follow a different rebase routine.

If I have one local commit

$ git reset HEAD^
$ git stash -u
$ git pull --rebase
$ git stash pop
$ git commit -m 'The same message I had before'

I have multiple local commits

$ git checkout -b temp
$ git checkout -
$ git pull --rebase --force
$ git rebase temp

@marcosvega91
Copy link
Member Author

You're as always, hahaha. I had updated the code but didn't commited yet. Now I have moved the test in the different relation files. I'll add some other test for other fields

Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

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

Thank you for your work on this!

@kettanaito kettanaito merged commit 8bb7419 into master Apr 23, 2021
@kettanaito kettanaito deleted the pr/fix_no_provided_relations branch April 23, 2021 12:52
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