contentful.rb icon indicating copy to clipboard operation
contentful.rb copied to clipboard

Querying for related entries by their contentType

Open 0xStarcat opened this issue 5 years ago • 1 comments

Hello! I'm having an issue trying to query for entries by a related entry's contentType.

I have 3 models - Resource, BlogPost and Video

I'm trying to query this model:

Resource

which has the single-reference field:

RESOURCE:

  • entry => BlogPost or Video

My query using the gem looks like this:

Content::Resource.all('fields.entry.sys.contentType.sys.id': 'blogPost', include: 4)

(the internal implementation of this should be fine, as include: 4 is passed correctly as an option along with the field query in the logs)

I get no errors.

What I get back is:

100 Resource entries, containing a mix of BlogPost and Video entries linked to the entry field

What i want is:

Only Resource entries with BlogPosts linked to the entry field

Any clue where the issue is? Thank you!

0xStarcat avatar May 07 '20 18:05 0xStarcat

Hi @0xStarcat!

Currently this is not possible with our Search API, you will have to filter manually by type, as our Search API only allows to use the relationship queries to filter by a value on the relationship and not by the relationship type itself.

Cheers

rubydog avatar Sep 18 '20 13:09 rubydog