Skip to content

FetchingRelationships

Mihael Šafarić edited this page Sep 2, 2019 · 4 revisions

When fetching a model via findOne method, or when fetching a list of models via find method, includeRelationships parameter can be passed.

includeRelationships is an array of strings which represents the model relationship names or the relationship names of nested models.

Valid includeRelationships values:

All the examples below assume fetching a user with specified relationships.

  • []

    • fetches a user without any additional calls
  • ['address']

    • fetches a user and when the user is fetched, it extracts address relationship URL from the response and fetches address resource
  • ['address.city']

    • fetches a user and when the user is fetched, it extracts address relationship URL from the response and fetches address resource
    • after the address is fetched, it extracts city relationship URL from the response and fetches city resource
  • ['address', 'address.city']

    • the same behaviour as ['address.city']
    • the library figures out that address will already be fetched as a part of address.city,so it skips that additional request