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

Reverse one-to-one relation not persisting in database #473

Open
AlmerCarbonEquity opened this issue Feb 14, 2024 · 0 comments
Open

Reverse one-to-one relation not persisting in database #473

AlmerCarbonEquity opened this issue Feb 14, 2024 · 0 comments

Comments

@AlmerCarbonEquity
Copy link

AlmerCarbonEquity commented Feb 14, 2024

I have the following model:

class Person(models.Model):
    user = models.OneToOneField("auth.User", on_delete=models.CASCADE, blank=True, null=True)

Now I want to make a recipe for a user that has a person to use in tests:

user = Recipe(User)
person = Recipe(Person)
user_with_person = user.extend(person=foreign_key(person))

when I check test_user = user_with_person.make() it has a test_user.person but when I check the database like this: User.objects.get(id=test_user.id).person it doesn't exist. I can create a person_with_user just fine. Is it not possible to define a reverse relation like this? I've made a small django project to showcase the issue: https://github.com/AlmerCarbonEquity/model-bakery-one-to-one

Expected behavior
I would expect User.objects.get(id=test_user.id).person to exist after test_user = user_with_person.make()

Versions

  • Python: [3.12.0]
  • Django [5.0.2]
  • Model Bakery [1.17.0]
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

No branches or pull requests

1 participant