-
Notifications
You must be signed in to change notification settings - Fork 399
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
How to attach RelatedFactoryList result to instance? #1092
Comments
Thanks for providing the full code example. It is, however, quite complex to read without prior knowledge of your project. By default, with a ttz = Ttz(name="TTZ 1")
session.add(ttz)
for i in range(2):
session.add(TtzFile(ttz=ttz, file_name="some_file_name", attachment_id=SomeUUID())) How would you write that piece of code without factories in order to get the |
Hi, @rbarrois ! I would write like this: files = []
for i in range(2):
file = TtzFile(file_name="some_file_name", attachment_id=SomeUUID())
files.append(file)
ttz = Ttz(name="TTZ 1", files=files)
session.add(ttz) As far as I now factory boy first creates main object and then related list. |
Your snippet wouldn't work, the However, if that's the way you'd write it, I suggest using a class FileFactory:
...
class TtzFactory:
files = factory.List([
factory.SubFactory(FileFactory),
factory.SubFactory(FileFactory),
]) This might work, instantiating the two File objects before attaching them. |
There was a mistake (copy paste). I fixed. Does SubFactory(FileFictory) return a stub object? As you can see TtzFile cannot be created without Ttz. Sorry, I can't check it because I don't have access to my computer. Well I ll try in a week. |
Thanks! Can you try the approach I suggested above, i.e a list of subfactories instead of a |
I'll try later in a week when I reach my computer. Thanks. |
Hi!
I have a question about using RelatedFactoryList in async SQLAlchemy. RelatedFactoryList creates instances but they are not attached to instance.
overridden for async base factory (from discussions in this repository):
models.py
factories.py
To make it available to get Ttz.files I have do refresh:
My question is it is the only way to get Ttz.files? I mean do I have to write _after_postgeneration method in each factory where I need to get related list?
The text was updated successfully, but these errors were encountered: