-
Notifications
You must be signed in to change notification settings - Fork 20
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
Creating a model instance with a relation but generating extra data without relation #60
Comments
Hey, I will give it a look today 👍 |
Just tested similar code on my machine and only models created like expected, so no duplicate ones. I also don't an error in your examples. Is there like a whole Laravel app that you can share for me to test? |
Hi, @christophrumpel thank you so much for help. I installed a new laravel and it goes the same, and I start to wonder does it is caused by the conflict between dependencies? My project: There are routes for you to check the result.(describe on readme) Thanks again! |
Thanks for getting back to me. I'm currently not at work this week but I will come back when I'm back at work. |
So back again here. Just gave it a quick look. I think it's because of this https://github.com/onlyu-bot/test-factory/blob/master/tests/Factories/InfoFactory.php#L26 You create a new product for every Info model inside the InfoFactory. |
@christophrumpel thank you so much! Yes, it is the root cause of generating extra data. I thought that I need to manually create the parent_id in the children factory, now I know that I don't need to do that! Thank you very much! |
thanks and glad it is working now. Maybe I need to make this more obvious through the docs. |
Hi,
that's say I create
n
model instances and each with a relation, but there output2n
rows of data in the table, andn
rows in the relation table.If I run
ProductFactory::new()->withFactory(InfoFactory::new(),'info')->create();
from tinker.The
products
table:The
infos
table:If I run
ProductFactory::new()->withFactory(InfoFactory::new(),'info',1)->times(10)->create();
from tinker.The
products
table:The
infos
table:These are two models:
The return of getDefaults method of
ProductFactory
:The return of getDefaults method of
InfoFactory
:I don't know why, any idea?
The text was updated successfully, but these errors were encountered: