0

Filtering on entities

I have Versions attached to Shots via the 'entity' field:

Version's schema:

{
...
'entity': {'data_type': 'entity',
            'display_name': 'Link',
            'editable': True,
            'source_columns': ['entity_type', 'entity_id']},
...
}

 

What I have in the database:

{
...
 'entity': {'id': 1326, 'name': '009x01', 'type': 'Shot', 'valid': 'valid'},
...
}

 

I want to filter Versions by Shots:

sg.find(('entity', 'include', {'id':1326, 'type': 'Shot'}))

 

'include' and 'in' don't work. I get:

Fault: <Fault 124: 'Operator (in) for Parameter entity is unrecognized or not allowed'>

 

What I am doing wrong?

5件のコメント

  • 0
    Avatar
    Gavin Greenwalt

    You aren't doing anything wrong. The API docs say you can use "include" but you can't. "is" functions the same as include.

    sg.find(('entity', 'is', {'id':1326, 'type': 'Shot'}))
    

    Should work.

  • 0
    Avatar
    Henry Precheur

    Yes it should work. Is that a bug in the API?

    PS: The previous code wasn't complete, here's what I am using:

    sg.find('Version', [('entity', 'in', [{'id':1326, 'type': 'Shot'}])])
  • 0
    Avatar
    Gavin Greenwalt

    Bug/Incomplete feature.  They said they were working on adding "include".

    Changing one letter should fix it in the mean time.    :)

    sg.find('Version', [('entity', 'is', [{'id':1326, 'type': 'Shot'}])])
  • 0
    Avatar
    Henry Precheur

    My initial question wasn't clear. Here is what I really wanted to do =)

    I have a list of 'Shots' and I want to find All the 'Versions' attached to
    them. I thought that I could pass a list to the 'in' operator, but apparently I
    can't.

    The following piece of code should be more explicit:

    sg.find('Version', [('entity', 'is', [{'id': 1326, 'type': 'Shot'},
                                          {'id': 1234, 'type': 'Shot'}])])

    This raises an exception:

    shotgun.Fault: <Fault 2: "Uncaught exception undefined method `base_class' for Array:Class in method version.find">


    I guess I can't use the 'is'/'in'/'includes' operator on entities :(

  • 0
    Avatar
    KP

    This is currently a bug in the API. We are going through the valid filter types at the moment to re-check which filter operators are actually valid for each field type and will update our docs accordingly. I know we have planned to fix this particular case.

    In the meantime, you could structure your query with multiple conditions and match on ANY of them which should have the same result with the following code:

     

        filters = [ ['entity', 'is', {'id': 1326, 'type': 'Shot'}],
                    ['entity', 'is', {'id': 1234, 'type': 'Shot'}] ]
        filter_operator = 'any'
        fields = ['content','entity']
        result = sg3.find('Version', filters = filters, filter_operator = filter_operator, fields = fields)
        filters = [ ['entity', 'is', {'id': 1326, 'type': 'Shot'}],
                    ['entity', 'is', {'id': 1234, 'type': 'Shot'}] ]
        filter_operator = 'any'    fields = ['content','entity']
        result = sg3.find('Version', filters = filters, filter_operator = filter_operator, fields = fields)
     

     

ログインしてコメントを残してください。