-
Notifications
You must be signed in to change notification settings - Fork 68
How to add meta tag to a resource identifier object in relationship ? #255
Comments
Refer to the documentation here: https://marshmallow-jsonapi.readthedocs.io/en/latest/quickstart.html#meta-information. Broadly, you use the |
Although having said that, if |
@TMiguelT
json api specification allows adding meta information in resource identifier objects
The documentation defines two types of meta information |
Ah sorry I didn't parse the JSON structure properly. Here's a formatted version: {
"data": {
"type": "products",
"id": "1",
"relationships": {
"processes": {
"data": [
{
"type": "processes",
"id": "15",
"meta": {
"order": "1"
}
}
]
}
}
}
} |
In any case, I believe you are right that this is a bug. Here's a simple test case derived from your example: https://gist.github.com/TMiguelT/932ae76b71c5cea79f45937b92a5ebe8 from marshmallow_jsonapi import fields, Schema
import json
class ProductSchema(Schema):
class Meta:
type_ = "products"
id = fields.String()
processes = fields.Relationship(
type_="processes",
id_field="id",
include_resource_linkage=True,
schema="ProcessSchema",
many=True
)
class ProcessSchema(Schema):
class Meta:
type_ = "processes"
id = fields.String()
meta = fields.ResourceMeta()
some_field = fields.String()
serialized = ProductSchema().dump({
"id": "1",
"processes": [
{
"id": 15,
"some_field": 123,
"meta": {
"order": "1"
}
}
]
})
print(json.dumps(serialized, indent=4))
# This assertion fails
assert 'meta' in serialized['data']['relationships']['processes']['data'][0] Basically, I'm asserting that the associated processes have a {
"data": {
"type": "products",
"id": "1",
"relationships": {
"processes": {
"data": [
{
"type": "processes",
"id": "15"
}
]
}
}
}
} The source of the issue is here, where we only ever use marshmallow-jsonapi/marshmallow_jsonapi/fields.py Lines 173 to 184 in 7d6b823
|
However, while this is a bug, I would be surprised if your order number needs to be a meta field, as I said. It sounds like it should be a relationship on |
In my case That's why i thought adding a meta information to resource link will help me identify the order of process. |
Oh, I see. It's "order" in the sense of the position in a list. I thought you meant order in the sense of "purchase". In that case I agree with you, that sounds like it could reasonably be a meta property, since it's not technically a field. On the other hand, the JSON API spec does say:
So, if you want, you could hack the |
How to add meta tag to a resource identifier in a relationship as shown in the example below
Example {json:api} data :
{
"data" : {
"type" : "products",
"id" : "1",
"relationships" : {
"processes" : {
"data" : [
{
"type" : "processes",
"id" : "15",
"meta" : {
"order" : "1"
}
}
]
}
}
}
}
The text was updated successfully, but these errors were encountered: