-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[5.3] Create factory modifiers #14241
Conversation
See Multiple Factory Types in Model Factories |
thanks, I am aware of the multiple factories types. unfortunately, unless I'm mistaken, they don't allow you to apply multiple 'modifications' to the factory. |
wondering if there are any thoughts on this? |
am i supposed to fix this @GrahamCampbell or do we let StyleCI handle it afterwards? |
Yeh, don't worry about StyleCI. :) |
Looking forward to this, pretty neat! |
Sorry this took so long. I renamed "modifiers" to "states"... pretty much works the same though 👍 |
@browner12: Nice! Could you update the docs as well? |
no problem. glad it worked out. was just going to ask, @taylorotwell would you like me to PR a docs update? |
i've come to find that I would would like to use factories a little different than is currently available. Currently you can
define
anddefineAs
factories. This works okay, but where I run into issues is where I have a lot of variable types. For example, I may have aBlog
that has apublished_at
field and anuser_id
field. TheBlog
can be published or unpublished, and it can have an author or be written by anonymous. I could have a published authored Blog, an unpublished authored Blog, a published anonymous Blog, and an unpublished anonymous Blog. Currently, I would have to write 5 different factory types for this.Ideally what I would like is 'modifiers' for each factory. To define them I would:
This would allow me to mix and match modifiers as needed. Then to use the factories I would
I believe this offers a lot more flexibility, and still allows people to do it the current way if they prefer.