A link between fields

I have a problem with the python API that is best explained with a demo scenario:

I have three entities, Person, Office and House.

A Person has one business address which can be a House or an Office. They also have potentially many rental properties which are all Houses.

When I create the fields “Business Address” and “Rental Properties”, shotgrid automatically creates corresponding fields in the Office and House entities.

If I trash the fields “Business Address” and “Rental Properties” their linked fields inside Office and House disappear as well. Similarly, If I revive from the trash, the other come back too.

How can a developer find out about this relationship between the fields by only using the python API. There seems to be nothing in the API returned schema to make this relationship clear.

https://developer.shotgridsoftware.com/python-api/reference.html?highlight=latest#shotgun_api3.shotgun.Shotgun.schema_field_read

Hey Sean,

I’m not particularly understanding this bit of your post:

I really shouldn’t rush these posts before leaving the office. I’ve edited the post now, does that make more sense?

1 Like

Haha, I get you :wink:

I understand your question now but I’m unsure I know the answer.

Indeed a field gets created for you on the other entity as its a linked field.
The short code for that field is also auto-generated.
I don’t know if you can query the “other field” throigh API, it would certainly be usefull!

From the schema for these fields on these entities, you can check the data_type key and value to know if the field is entity or multi-entity. Then with this knowledge you can then learn what the valid_types key value is and at least know which entities it’s expecting to connect to. Then the created_at and created_by fields on the field entities themselves are the only clues you could use to discern which two fields on connected entities are linked together as these should be the same values. SG does also tend to use a naming convention for the second linked field, so if you create a few entity<->entity connections you can start to see the trend and perhaps use the naming of a field to identify this more specifically.

Usually this is a good bet… but it’s not a proper answer.

1 Like