Directly construct a related document. It will be lazily initialized from document
on first use,
so we need to provide an id and a type here so that the resource can find itself in document
.
IdMismatchError when id
was not found in the given document
Protected
Readonly
documentThe parent document that contains this resource
Readonly
idThe id of this resource
Readonly
typeThe resource type
Object containing all attributes of this resource
Object containing all Links defined by this resource
https://jsonapi.org/format/1.0/#document-links
Object containing all meta data of this resource
The raw JSON:API data of this resource
Proxy providing all Documents reachable via related
links in relationships.
For this JSON:API document
{
"data": {
"type": "articles",
"id": "1",
"relationships": {
"author": {
"links": {"related": "http://example.com/people/1"}
},
"reviewer": {
"links": {"related": "http://example.com/people/12"}
}
}
}
}
calling relatedDocuments
on the primary articles resource will give you access to the following data:
{
author: Document(...),
reviewer: Document(...)
}
As this is only a proxy object, calling relatedDocuments
does not yet fetch any related documents.
Only when accessing a specific related document (e.g. calling article.relatedDocuments['author']
) is the
new document actually requested from the server.
Proxy providing all singular Resources reachable via relationships from this resource.
For this JSON:API document
{
"data": {
"type": "articles",
"id": "1",
"relationships": {
"author": {
"data": {"type":"people", "id":"1"}
},
"reviewer": {
"data": {"type":"people", "id":"12"}
}
}
},
"included": [...]
}
calling relatedResource
on the primary articles resource will give you access to the following data:
{
author: RelatedResource(...),
reviewer: RelatedResource(...)
}
This accessor is a shortcut so that you do not have to go through relationships
manually every time.
Writing
const author = await article.relatedResource['author'];
is equivalent to
const author = await article.relationships['author'].resource();
As this shortcut uses the resource method, it prefers resource linkage (i.e. id/type pairs in data
)
to related
links should both be present in the relationship. You can use the resourceFromRelatedLink
method if you need to fetch a related resource via link instead of resource linkage.
As this is only a proxy object, calling relatedResource
will not yet construct any RelatedResource
instances. Only when accessing a specific related resource (e.g. calling article.relatedResource['author']
)
is the new resource actually constructed.
Proxy providing all multiple Resources reachable via relationships from this resource.
For this JSON:API document
{
"data": {
"type": "articles",
"id": "1",
"relationships": {
"comments": {
"data": [{"type":"comments", "id":"1"}, {"type":"comments", "id":"2"}]
},
"ratings": {
"data": [{"type":"ratings", "id":"1"}, {"type":"ratings", "id":"2"}]
}
}
},
"included": [...]
}
calling relatedResources
on the primary articles resource will give you access to the following data:
{
comments: [
RelatedResource(...),
RelatedResource(...)
],
ratings: [
RelatedResource(...),
RelatedResource(...)
]
}
This accessor is a shortcut so that you do not have to go through relationships
manually every time.
Writing
const comments = await article.relatedResources['comments'];
is equivalent to
const comments = await article.relationships['comments'].resources();
As this shortcut uses the resources method, it prefers resource linkage (i.e. id/type pairs in data
)
to related
links should both be present in the relationship. You can use the resourcesFromRelatedLink
method if you need to fetch related resources via link instead of resource linkage.
As this is only a proxy object, calling relatedResources
will not yet construct any RelatedResource
instances. Only when accessing a specific related resource (e.g. calling article.relatedResources['comments']
)
are the new resources actually constructed.
Object containing all Relationships defined by this resource
https://jsonapi.org/format/1.0/#document-resource-object-relationships
Protected
getLooks up the matching resource in the parent Document. All primary resources (those in the data
member)
and all included resources (those in the included
member) are searched.
IdMismatchError if the resource is not found or found multiple times
SchemaError when rawData
does not look like a JSON:API resource object
Generated using TypeDoc
A resource contained in the top level
included
member of a Document or linked via href.This resource is initialized lazily on demand when its getData method is first called. The resource then looks for its id and type (given at construction) in the parent document
data
andincluded
members to find its raw data.Normally a related resource is obtained via the relatedResource and relatedResources accessors or the resource and resources methods.
Example
Remarks
Methods and accessors marked as
memoized
are only executed once per instance (the first time they are called) and return a cached result on subsequent calls.