-
Notifications
You must be signed in to change notification settings - Fork 148
Closed as not planned
Closed as not planned
Copy link
Milestone
Description
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
...
endWithout 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": {}
}
]
}kln
Metadata
Metadata
Assignees
Labels
No labels