-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
feat(sqla_factory): added __set_association_proxy__ attribute #629
base: main
Are you sure you want to change the base?
Conversation
|
||
from polyfactory.factories.sqlalchemy_factory import SQLAlchemyFactory | ||
|
||
if __version__.startswith("2"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this required? It would be great to test this syntax for both 1 and 2
|
||
By default, relationships will not be set. This can be overridden via ``__set_relationships__``. | ||
By default, ``__set_relationships__`` is set to ``False``. If it is ``True``, all fields with the SQLAlchemy `relationship() <relationship()_>`_ will be included in the resulting mock dictionary created by ``build`` method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, ``__set_relationships__`` is set to ``False``. If it is ``True``, all fields with the SQLAlchemy `relationship() <relationship()_>`_ will be included in the resulting mock dictionary created by ``build`` method. | |
By default, ``__set_relationships__`` is set to ``False``. If it is ``True``, all fields with the SQLAlchemy `relationship() <relationship()_>`_ will be included in the result created by ``build`` method. |
|
||
.. literalinclude:: /examples/library_factories/sqlalchemy_factory/test_example_2.py | ||
:caption: Setting relationships | ||
:language: python | ||
|
||
.. note:: | ||
In general, foreign keys are not automatically generated by ``.build``. This can be resolved by setting the fields yourself and/or using ``create_sync``/ ``create_async`` so models can be added to a SQLA session so these are set. | ||
In general, ForeignKey fields are automatically generated by ``build`` method because :class:`__set_foreign_keys__ <polyfactory.factories.sqlalchemy_factory.SQLAlchemyFactory.__set_foreign_keys__>` is set to ``True`` by default. But their values can be overwritten by using ``create_sync``/ ``create_async`` methods, so SQLAlchemy ORM creates them. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the last sentence correct always? Would that only be the case if a relationship is present?
Documentation preview will be available shortly at https://litestar-org.github.io/polyfactory-docs-preview/629 |
Hi, @adhtruong! More detailed about #629 (comment): I have rewritten this part more clearly. |
Thanks for updating! LGTM |
@all-contributors add @nisemenov for code doc |
I've put up a pull request to add @nisemenov! 🎉 |
Description
Closes