diff options
author | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2016-02-09 23:57:31 +0100 |
---|---|---|
committer | Raphaël Barrois <raphael.barrois@polytechnique.org> | 2016-02-09 23:57:31 +0100 |
commit | 229d43874723f36b380eb49e53538bf21511fa5a (patch) | |
tree | 2f12ee3eaf241cd05e73a0cff3a85ea519c06a54 /docs/reference.rst | |
parent | 4172dd686ce483191b33e3189d716f11b3da921e (diff) | |
download | factory-boy-229d43874723f36b380eb49e53538bf21511fa5a.tar factory-boy-229d43874723f36b380eb49e53538bf21511fa5a.tar.gz |
Clarify the use of SelfAttribute in RelatedFactory (Closes #264)
Diffstat (limited to 'docs/reference.rst')
-rw-r--r-- | docs/reference.rst | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/docs/reference.rst b/docs/reference.rst index 6398d9a..b5ccd16 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -1412,6 +1412,23 @@ If a value if passed for the :class:`RelatedFactory` attribute, this disables 1 +.. note:: The target of the :class:`RelatedFactory` is evaluated *after* the initial factory has been instantiated. + This means that calls to :class:`factory.SelfAttribute` cannot go higher than this :class:`RelatedFactory`: + + .. code-block:: python + + class CountryFactory(factory.Factory): + class Meta: + model = Country + + lang = 'fr' + capital_city = factory.RelatedFactory(CityFactory, 'capital_of', + # factory.SelfAttribute('..lang') will crash, since the context of + # ``CountryFactory`` has already been evaluated. + main_lang=factory.SelfAttribute('capital_of.lang'), + ) + + PostGeneration """""""""""""" |