Contentful logo

Contentful Community

Deep search by incoming links and multi-tenancy

Hi,

We’re trying to adopt headless approach to our Content model and it’s going well so far.
However, there is one limitation/constraint which makes content modeling a bit difficult.

We’re trying to ‘mimic’ multi-tenancy model by introducing sort of Root content type with ‘tenantId’ (customer Id) as a container for other related content types.
Just an example, you have your ‘Policy for Company X’ as a content type, and within you might have ‘Policy Item’ which might have set of different ‘Rules’ as a child.
So, effectively, the schema looks like ‘Policy->Item->Rule’

The major problem with this model, today we specify tenantId for Root content type only, and this approach doesn’t allow us to search via API for the related child models of the same tenant on the deep levels (like Rule in example above) for the same tenantId.
There is a concept of ‘incoming links’ in Contentful, but seems that it’s limited to one level of relationship only. So, in our case, we can easily find all the ‘Items’ whose parent ‘Policy’ has specific tenantId. But, we can’t do the same for the ‘Rule’ level.

So, could you please suggest some approach to model content in a hierarchical way, so we can support (mimic?) multi-tenancy.
And also, it would be great to know if/how it’s possible in the hierarchy above to traverse by content tree via API and limit the search scope based on the ‘incoming link’ of the parent.

Thanks.

Hi Dzmitry, as far as I understood, you would like to make one API call to retrieve all the nested/linked content of ‘Policy’, is that right? if this is the goal, you could use include parameter: https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/links.

Alma,

Thanks for picking this up.

Effectively, I’d like to get Rule level entities who’s grand parent (Policy) has specific incoming link (belongs to particular tenant Id).

I’ll take a look at the ‘include’ param as you suggested and back to you with result.

Thanks!