Linked fields

This is possibly just my ignorance, but whereas in Shotgun itself it's quite quick/easy to pull in linked fields (e.g. a Task's Shot's delivery date) I haven't found a way to do this through the API - it seems you have to fetch your task, then do a second lookup for the shot, which can be pretty slow and painful when doing a batch job on a lot of tasks. Any tips?


  • 0
    Mike Romey

    Here is what I tend to do.  Keep in mind we have a crazy shotgun server with a lot of memory.  I think it's got something like 96 gigs or RAM. 


    I grab all the tasks with a filter to limit the return data to only the data I need.  I do this in one API request.  Then I do another request in the other entity where I have linked data.  If possible I make another filter for that request based off of some values from the first API request.  I recently found some very slick ways to assemble this filter.  I can show you that tomorrow.  Then I do all my labor of finding the corresponding shot for each task request inside of some loops inside of python.  Doing so in this manner allows me to only make 2 large api requests that return the bare minimum amount of data rather than hundres of small requests. It makes the painful less painful.  Don't be scared to assemble very complicated filters with the API.  It will save you a lot when it comes to doing large batch jobs.


    I hope this helps.





  • 0
    Isaac Reuben

    Hey Andy,


    Getting linked fields is something we'll be adding the the next rev of the api, version 3.  Our plan is to have a developer preview of that working in 1.8, with an official release of it in 1.9.  As Romey mentioned above, there are ways to work around this in the current api, but real support for it is coming!

    - Isaac

  • 0
    Dan Shumaker

    I think I'm asking the same thing.  Essentially I want an "inner join" I think.   I'd like to be able to do something like this:

    filters = [ ['entity','is', {'type':'Shot', 'id':ShotId}] ]
    order = [{'field_name':'sg_pin_code_name->id','direction':'desc'}]
    fields = ['sg_pin_code_name']

    pinList = sg.find("Version", filters, fields, order)

    I'm looking for a list of entities ("sg_pin_code_name" --CustomEntity01--in this case) that are linked to versions.  I'm also asking (hoping) that the list can be sorted by the id of that entity.  I'm guessing I can't do the "->" in the order list but like Romey says it's easy to do in the shotgun interface.  When you want to see a linked entities fields in a view they show up with a "->" in the column titles by default.

    You say it's available in this api release?  I'm running api 3 beta 3 and 1.8,  is it possible now?

    Many thanks,


  • 0
    Tony Pelle

    Did this ever make it into api3?  Joins on columns returned and filtered columns would be utterly fantastic.  Right now we're doing what Mike suggested, but find large queries to be slow or being unable to distill our queries to a minimal number (find all shots in a sequence, then find all lighting versions for all shots in those sequence, then find all artists and all tasks for lighting versions for all shots in the desired sequence).  I'm assuming that support for joins in the api queries will result in faster queries...





  • 0

    In API3, you can now do queries like this to get all of the Tasks for a Shot and include the Shot's delivery date in the results:

    result = sg.find('Task', [ ['entity', 'is', {'type':'Shot', 'id':123}] ], ['content', 'entity.Shot.sg_delivery_date'])

    You can also use the same deep linking syntax in the filters:


    result = sg.find('Task', [ ['entity.Shot.sg_delivery_date', 'is', '2010-07-14'] ], ['content', 'user', 'entity.Shot.sg_delivery_date'])


    Right now you can only link through 1 step away so you can't do something like entity.Shot.sg_sequence.Sequence.sg_delivery_date, but that will come...

  • 0

    Any progress on multi-step linking? I would have hoped this would be in the API by now, but it doesn't seem to be.