When lazy loading polymorphic relationships.. when including the relationship, the relationship object comes through but the relationship data does not.
# provider_lead_serializer.rb
class ProviderLeadSerializer
include FastJsonapi::ObjectSerializer
belongs_to :owner, polymorphic: true, lazy_load_data: true
...
end
# agent_serializer.rb
class AgentSerializer
include FastJsonapi::ObjectSerializer
...
end
Without including the relationship, the data is not loaded (as expected):
ProviderLeadSerializer.new(provider_lead)
yields:
{
"data": [
{
"id": 123,
"type": "provider_lead",
"attributes": {},
"relationships": {
"owner": { }
}
}
],
"included": []
}
Then, I want to explicitly include the owner relationship:
ProviderLeadSerializer.new(provider_lead, { include: [:owner] })
yields:
{
"data": [
{
"id": 123,
"type": "provider_lead",
"attributes": {},
"relationships": {
"owner": { }
}
}
],
"included": [
{
"id": 456,
"type": "agent",
"attributes": {}
}
]
}
^^^ This is missing the data on provider_lead.relationships. If i remove lazy_load_data: true, everything works as expect.
Expected JSON would be:
{
"data": [
{
"id": 123,
"type": "provider_lead",
"attributes": {},
"relationships": {
"owner": {
"data": {
"id": 456,
"type": "agent"
}
}
}
}
],
"included": [
{
"id": 456,
"type": "agent",
"attributes": {}
}
]
}
When lazy loading polymorphic relationships.. when including the relationship, the relationship object comes through but the relationship data does not.
Without including the relationship, the data is not loaded (as expected):
yields:
{ "data": [ { "id": 123, "type": "provider_lead", "attributes": {}, "relationships": { "owner": { } } } ], "included": [] }Then, I want to explicitly include the
ownerrelationship:yields:
{ "data": [ { "id": 123, "type": "provider_lead", "attributes": {}, "relationships": { "owner": { } } } ], "included": [ { "id": 456, "type": "agent", "attributes": {} } ] }^^^ This is missing the data on
provider_lead.relationships. If i removelazy_load_data: true, everything works as expect.Expected JSON would be:
{ "data": [ { "id": 123, "type": "provider_lead", "attributes": {}, "relationships": { "owner": { "data": { "id": 456, "type": "agent" } } } } ], "included": [ { "id": 456, "type": "agent", "attributes": {} } ] }