You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've created an ORM factory that generates a must-have relationship using SubFactory by default.
I expected it'll be replaced if I provide either the foreign key ID or the related object, but it didn't.
Indeed, factory_boy does not inspect your model structure; nor is it aware of the magic performed by the ORM library.
In its view, the address and address_id fields are unrelated, and live separate lives.
If you pass in (address_id=address_id, address=None), the second part will prevent the subfactory to be built.
You'll have to check whether your ORM behaves as you'd expect when calling User(address=None, address_id=42)
If that works, I'll be glad to add that suggestion to the documentation's common recipes section!
Description
I've created an ORM factory that generates a must-have relationship using
SubFactory
by default.I expected it'll be replaced if I provide either the foreign key ID or the related object, but it didn't.
To Reproduce
There's a working example below.
Model / Factory code
The issue
I expected that the created user's address would be the address I provided, but it seems that it is covered by the address created by the subfactory.
The text was updated successfully, but these errors were encountered: