Question: how to detect relationships #846
-
When data is requested , attributes and relationships are merged into one data object it seems. Which is nice. But i need a list of relationships to know which subrequests to make. For example , a field may contain an array of relationships. I don't know which those will be ahead of time. So after the first request , i have to make a separate call to fetch all relationships . But how can j reliably tell if a property was original a relationship or not ? Just assuming it was a relationship when an 'id' and 'type' property are present feels a bit dirty. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Sorry, I'm not really understanding what this question is asking. Resource linkages are defined in https://jsonapi.org/format/#document-resource-object-linkage (an object or array of objects with |
Beta Was this translation helpful? Give feedback.
-
Since the 'relationships' key from the output document is removed , how can
i differentiate between what was a relationship and what is a normal
attribute value ?
…On Tue, Apr 18, 2023, 00:14 James Harris ***@***.***> wrote:
Sorry, I'm not really understanding what this question is asking.
Resource linkages are defined in
https://jsonapi.org/format/#document-resource-object-linkage
—
Reply to this email directly, view it on GitHub
<#845 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALMD2DX5EHMSGUMYJ2IH5ILXBW6D5ANCNFSM6AAAAAAXBV5MGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Relationships will always be an object containing a I.e {
id: '89',
type: 'post',
content: 'My post content',
author: {
data: {
id: '42',
type: 'people',
name: 'John'
}
},
comments: {
data: [
{
id: '43',
type: 'comment',
text: 'A comment',
author: {
data: {
id: '3',
type: 'people',
name: 'Bob'
}
}
}
]
}
} |
Beta Was this translation helpful? Give feedback.
-
Oh, stupid me :(. Missed that data wasn't flattened . That'll be specific
enough . Thanks !
…On Tue, Apr 18, 2023, 11:50 James Harris ***@***.***> wrote:
Relationships will always be an object containing a data attribute (which
itself will always contain id, type and any attributes from the
relationship.
I.e author and comments are 1-1 and 1-many relationships here:
{
id: '89',
type: 'post',
content: 'My post content',
author: {
data: {
id: '42',
type: 'people',
name: 'John'
}
},
comments: {
data: [
{
id: '43',
type: 'comment',
text: 'A comment',
author: {
data: {
id: '3',
type: 'people',
name: 'Bob'
}
}
}
]
}}
—
Reply to this email directly, view it on GitHub
<#845 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ALMD2DQP56Q4SUCVBNP6VUDXBZPVZANCNFSM6AAAAAAXBV5MGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
Relationships will always be an object containing a
data
attribute (which itself will always containid
,type
and any attributes from the relationship. 1-1 relationships will havedata
as an object and 1-many relationships will havedata
as an array of objectsI.e
author
andcomments
are 1-1 and 1-many relationships here: