-
Notifications
You must be signed in to change notification settings - Fork 21
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
Features request #27
Open
hyuti
wants to merge
24
commits into
bluele:master
Choose a base branch
from
hyuti:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Features request #27
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dev hyuti
docs: remove comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi folks, I create this PR to solve some problems I face while i was working on other project which used this repository. By the way, my English is not quite good, so please forgive me if I make any mistakes.
Here are problems:
Let say we have following structs:
This is the most common relationship where a customer can have one or more orders. And I know in the most of cases we show relationship between them through the way we embed Customer into Order struct. However, there are some cases that we just want some fields to represent the relationship between entities such as the above example which Order entity only has ID of Customer.
So that would be great this repository give us some ways to work around this situation. So I defined a type called
Formatter
which is alias offunc(interface{}) (interface{}, error)
For instance, if we only want ID field from Customer after SubFactory populated for us, we pass formatters as arguments to
SubFactory
functionLet say you have following struct:
you need to ensure customer id field is generated through subfactory or whatever before customer name is generated, but surprisingly you mixed the order of these two fields or the above struct comes from another package which is not owned by you so that you cannot modify the order as you wish which means that the above struct should be as following to meet our requirements:
Old implementations limit this usecase, we have to jumb back to the file where the struct lives and modify the order of the fields in the struct, or even in the worse case, the struct is not yours which is owned by someone else, so you cannot modify the struct as I mention, there is still a way for this case, you copy the struct. Although we still have ways to handle these cases, why don't we enhance the repository to meet our requirements conveniently.
See example in ordering-attr-with-formatter in the example folder for more detail on how usage.
Feel free to feedback!
Thanks!