summaryrefslogtreecommitdiff
path: root/docs/reference.rst
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-03 22:10:42 +0100
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-03-03 22:10:42 +0100
commit9422cf12516143650f1014f34f996260c00d4c0a (patch)
tree879113f8d65560dc9fd435872ffbf1cc44af01de /docs/reference.rst
parentf8708d936be1aa53a8b61f95cda6edcdbd8fc00a (diff)
downloadfactory-boy-9422cf12516143650f1014f34f996260c00d4c0a.tar
factory-boy-9422cf12516143650f1014f34f996260c00d4c0a.tar.gz
Allow symbol names in RelatedFactory (Closes #30).
This works exactly as for SubFactory. Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
Diffstat (limited to 'docs/reference.rst')
-rw-r--r--docs/reference.rst33
1 files changed, 24 insertions, 9 deletions
diff --git a/docs/reference.rst b/docs/reference.rst
index efb70e8..e2246aa 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -215,7 +215,7 @@ factory_boy supports two main strategies for generating instances, plus stubs.
object, then save it:
.. code-block:: pycon
-
+
>>> obj = self._associated_class(*args, **kwargs)
>>> obj.save()
>>> return obj
@@ -849,18 +849,32 @@ To support this pattern, factory_boy provides the following tools:
RelatedFactory
""""""""""""""
-.. class:: RelatedFactory(some_factory, related_field, **kwargs)
+.. class:: RelatedFactory(factory, name='', **kwargs)
.. OHAI_VIM**
-A :class:`RelatedFactory` behaves mostly like a :class:`SubFactory`,
-with the main difference that it should be provided with a ``related_field`` name
-as second argument.
+ A :class:`RelatedFactory` behaves mostly like a :class:`SubFactory`,
+ with the main difference that the related :class:`Factory` will be generated
+ *after* the base :class:`Factory`.
+
+
+ .. attribute:: factory
+
+ As for :class:`SubFactory`, the :attr:`factory` argument can be:
+
+ - A :class:`Factory` subclass
+ - Or the fully qualified path to a :class:`Factory` subclass
+ (see :ref:`subfactory-circular` for details)
+
+ .. attribute:: name
+
+ The generated object (where the :class:`RelatedFactory` attribute will
+ set) may be passed to the related factory if the :attr:`name` parameter
+ is set.
+
+ It will be passed as a keyword argument, using the :attr:`name` value as
+ keyword:
-Once the base object has been built (or created), the :class:`RelatedFactory` will
-build the :class:`Factory` passed as first argument (with the same strategy),
-passing in the base object as a keyword argument whose name is passed in the
-``related_field`` argument:
.. code-block:: python
@@ -882,6 +896,7 @@ passing in the base object as a keyword argument whose name is passed in the
>>> City.objects.get(capital_of=france)
<City: Paris>
+
Extra kwargs may be passed to the related factory, through the usual ``ATTR__SUBATTR`` syntax:
.. code-block:: pycon