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
{{ message }}
Repository navigation
Commit 17a9c2b
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: user_guide_src/source/outgoing/api_transformers.rst
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -147,6 +147,14 @@ resource name. Inside these methods, you can access the current resource being t
147
147
148
148
.. literalinclude:: api_transformers/009.php
149
149
150
+
.. important::
151
+
When transforming related resources inside an include method, always use ``$this->transformRelated()`` instead of manually instantiating a new transformer (e.g., ``new PostTransformer()``).
152
+
153
+
The ``transformRelated()`` method provides two major benefits:
154
+
155
+
1. It automatically determines whether to transform a single item or a collection based on the provided data.
156
+
2. It prevents **Global State Leakage**, ensuring that the parent request's query parameters (like ``?include=`` or ``?fields=``) do not accidentally bleed into the child transformer and cause unexpected infinite loops or `ApiException`.
157
+
150
158
Note how the include methods use ``$this->resource['id']`` to access the ID of the user being transformed.
151
159
The ``$this->resource`` property is automatically set by the transformer when ``transform()`` is called.
0 commit comments