-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
Recipes with foreign_key
and one_to_one=True
breaks
#204
Comments
foreign_key
and one_to_one=True
breaks
Hi @walison17 thanks for opening this issue. Probably the fix for this should also fix #28 because, even though they differ a little bit on their contexts. But, actually, I fell that the modeling you've used to describe your problem is not correct. Because, every time you user_with_profile = baker.make_recipe("yourapp.profile").user Also, by using the recipes the way you've defined, you'll always end up with more users than you're probably expecting. This is because, to make a Profile instance, baker is obligated to create a user because of the FK. So, if you call the
This is one of the problems of using Recipes combined with related name to create objects. I'm not so sure if it's possible to fix this though, since the usage of |
I don't know, maybe we're missing some type of dependency inversion here to make the tests easier and more semantics. I don't know, something like: # baker_recipes.py
profile = Recipe("yourapp.profile")
user_with_profile = from_recipe_fk('profile', 'user', username='foo') This method would output a special type of recipe that depends on a previous one to work. So it'll:
@amureki or @anapaulagomes what do you think about this? |
I'm closing this issue since the same problem was already documented in #97. |
actual at version 1.15.0 |
Recipes that uses reverse relationship
foreign_key
andone_to_one=True
break when call makeWhat you expected.
2 users created and 2 profiles created attached to each other.
What happened instead.
Versions
Python: 3.9.3
Django: 3.1.8
Model Bakery: 1.3.2
The text was updated successfully, but these errors were encountered: