Skip to content

Commit 86f64f3

Browse files
SG-21729 Update docs for entity fields. (#279)
* SG-21729 Update docs for entity fields. * Update docs/cookbook/usage_tips.rst Co-authored-by: Shayna Duguid <shayna.cohen@shotgunsoftware.com> --------- Co-authored-by: Shayna Duguid <shayna.cohen@shotgunsoftware.com>
1 parent 1da5385 commit 86f64f3

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

docs/cookbook/usage_tips.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ Multi-threading
3131
The ShotGrid API is not thread-safe. If you want to do threading we strongly suggest that you use
3232
one connection object per thread and not share the connection.
3333

34+
.. _entity-fields:
35+
3436
*************
3537
Entity Fields
3638
*************
3739

38-
When you do a :meth:`~shotgun_api3.Shotgun.find` call that returns a field of type entity or
39-
multi-entity (for example the 'assets' column on Shot), the entities are returned in a standard
40-
dictionary::
40+
When you do a :meth:`~shotgun_api3.Shotgun.find` or a :meth:`~shotgun_api3.Shotgun.create` call
41+
that returns a field of type **entity** or **multi-entity** (for example the 'Assets' column on Shot),
42+
the entities are returned in a standard dictionary::
4143

4244
{'type': 'Asset', 'name': 'redBall', 'id': 1}
4345

@@ -260,6 +262,8 @@ ShotGrid logger to a higher level::
260262
Optimizations
261263
*************
262264

265+
.. _combining-related-queries:
266+
263267
Combining Related Queries
264268
=========================
265269
Reducing round-trips for data via the API can significantly improve the speed of your application.
@@ -285,7 +289,7 @@ With "field hopping" you can combine these queries into::
285289
sg_shots = sg.find("Shot", [['project.Project.name', 'is', project_name]], ['code'])
286290

287291
As you can see above, the syntax is to use "``.``" dot notation, joining field names to entity
288-
types in a chain. In this example we start with the field ``project`` on the Shot entity, then
292+
types in a chain. In this example we start with the field ``project`` on the ``Shot`` entity, then
289293
specify we're looking for the "name" field on the Project entity by specifying ``Project.name``.
290294

291295
Now that we've demonstrated querying using dot notation, let's take a look at returning linked data
@@ -296,7 +300,10 @@ by adding the status of each Sequence entity associated with each Shot in our pr
296300
sg_shots = sg.find("Shot", [['project.Project.name', 'is', project_name]],
297301
['code', 'sg_sequence.Sequence.sg_status_list'])
298302

303+
The previous examples use the :meth:`~shotgun_api3.Shotgun.find` method. However, it's also applicable
304+
to the :meth:`~shotgun_api3.Shotgun.create` method.
305+
299306
.. note::
300-
Due to performance concerns with deep linking, we only support using dot syntax chains for
307+
Due to performance concerns with deep linking, we only support using dot notation chains for
301308
single-entity relationships. This means that if you try to pull data through a multi-entity
302309
field you will not get the desired result.

shotgun_api3/shotgun.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,9 @@ def find_one(self, entity_type, filters, fields=None, order=None, filter_operato
874874
:ref:`additional_filter_presets`
875875
:returns: Dictionary representing a single matching entity with the requested fields,
876876
and the defaults ``"id"`` and ``"type"`` which are always included.
877+
878+
.. seealso:: :ref:`entity-fields`
879+
877880
:rtype: dict
878881
"""
879882

@@ -910,7 +913,7 @@ def find(self, entity_type, filters, fields=None, order=None, filter_operator=No
910913
{'code': 'Wet Gopher', 'id': 149, 'sg_asset_type': 'Character', 'type': 'Asset'}]
911914
912915
You can drill through single entity links to filter on fields or display linked fields.
913-
This is often called "deep linking" or using "dot syntax".
916+
This is often called "deep linking" or using "dot notation".
914917
915918
.. seealso:: :ref:`filter_syntax`
916919
@@ -933,10 +936,13 @@ def find(self, entity_type, filters, fields=None, order=None, filter_operator=No
933936
:param str entity_type: Shotgun entity type to find.
934937
:param list filters: list of filters to apply to the query.
935938
936-
.. seealso:: :ref:`filter_syntax`
939+
.. seealso:: :ref:`filter_syntax`, :ref:`combining-related-queries`
937940
938941
:param list fields: Optional list of fields to include in each entity record returned.
939942
Defaults to ``["id"]``.
943+
944+
.. seealso:: :ref:`combining-related-queries`
945+
940946
:param list order: Optional list of dictionaries defining how to order the results of the
941947
query. Each dictionary contains the ``field_name`` to order by and the ``direction``
942948
to sort::
@@ -970,6 +976,9 @@ def find(self, entity_type, filters, fields=None, order=None, filter_operator=No
970976
:ref:`additional_filter_presets`
971977
:returns: list of dictionaries representing each entity with the requested fields, and the
972978
defaults ``"id"`` and ``"type"`` which are always included.
979+
980+
.. seealso:: :ref:`entity-fields`
981+
973982
:rtype: list
974983
"""
975984

@@ -1332,10 +1341,16 @@ def create(self, entity_type, data, return_fields=None):
13321341
to the server automatically.
13331342
:param list return_fields: Optional list of additional field values to return from the new
13341343
entity. Defaults to ``id`` field.
1344+
1345+
.. seealso:: :ref:`combining-related-queries`
1346+
13351347
:returns: Shotgun entity dictionary containing the field/value pairs of all of the fields
13361348
set from the ``data`` parameter as well as the defaults ``type`` and ``id``. If any
13371349
additional fields were provided using the ``return_fields`` parameter, these would be
13381350
included as well.
1351+
1352+
.. seealso:: :ref:`entity-fields`
1353+
13391354
:rtype: dict
13401355
"""
13411356

0 commit comments

Comments
 (0)