-
Notifications
You must be signed in to change notification settings - Fork 1
FetchingRelationships
Mihael Safaric edited this page Jul 27, 2020
·
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 or RelationshipDescriptor
s which represent the model relationship indentificators or the relationship indentificators of nested models.
When passing RelationshipDescriptor
s, different request options can be specified for each subsequent request.
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 fetchesaddress
resource
- fetches a user and when the user is fetched, it extracts
-
[{ name: 'address' }]
- the same behaviour as
['address']
, but instead of a simple string,RelationshipDescriptor
is passed
- the same behaviour as
-
[{ name: 'address', options: { params: { size: '100' } } }]
- the same behaviour as
[{ name: 'address' }]
, but different paramaters are used when doing the "address" request
- the same behaviour as
-
['address.city']
- fetches a user and when the user is fetched, it extracts
address
relationship URL from the response and fetchesaddress
resource - after the address is fetched, it extracts
city
relationship URL from the response and fetchescity
resource
- fetches a user and when the user is fetched, it extracts
-
['address', 'address.city']
- the same behaviour as
['address.city']
- the library figures out that
address
will already be fetched as a part ofaddress.city
, so it skips that additional request
- the same behaviour as
-
[{ name: 'address', options: { params: { size: '100' } } }, 'address.city']
- the same behaviour as
['address', 'address.city']
, but different paramaters are used when doing the "address" request -
'address.city'
request would be the same as in the previous example
- the same behaviour as