Include with filter & multiple fields in reference



I’m trying to fetch multiple fields of a reference while filtering it.

This works, but it seems very redundant (especially when the filter is more complicated than this one):

MyType.fetch({include: "myRef.(name == 'foo').value, \
                        myRef.(name == 'foo').startDate, \
                        myRef.(name == 'foo').endDate})

Is there a cleaner way? Fetching the whole reference could be an option as my type is small but I got no luck with [myRef.(name == 'foo')] or myRef.(name == 'foo').[this] (wild guesses reading at the doc).



Yes, you can use the Obj notation form of the include string and add a dot query as well:

Example of Obj notation for including several nested fields:

  include: "{myRef: [value, startDate, endDate]}"

Example of Obj notation while filtering on MyType.myRef:

  include: "{myRef: [value, startDate, endDate]}.(name == 'foo')"

Note that the filter name == 'food' will not omit MyType objs that don’t have a myRef with name "foo"—it will still return all MyType objs. But it will only include myRef on those objs if is "foo".


Additionally, you can follow this same format of the include structure in nested type-traversals:

  include: "{myRef: [value, startDate, endDate, {refrenceFieldToSecondType: [fieldAFromSecondType, fieldBFromSecondType] } ] }"

just follow the same format, where the field name and resulting object are contained in {} and the fields on the reference object are contained in [].