-
Notifications
You must be signed in to change notification settings - Fork 148
Open
Description
Problem
class ApplicationSerializer
include JSONAPI::Serializer
def self.has_many(name, options = {}, &block)
super(name, options.merge(lazy_load_data: true), &block)
end
def self.has_one(name, options = {}, &block)
super(name, options.merge(lazy_load_data: true), &block)
end
def self.belongs_to(name, options = {}, &block)
super(name, options.merge(lazy_load_data: true), &block)
end
def self.has_and_belongs_to_many(name, options = {}, &block)
super(name, options.merge(lazy_load_data: true), &block)
end
end
class ASerializer < ApplicationSerializer
has_many :b
end
class BSerializer < ApplicationSerializer
belongs_to :c, polymorphic: true
end
I wrote the code above and sent a request with include=a.c to A contoller.
It seems that lazy_load_data: true does not work as expected for multilevel and polymorphic or STI relationships defined more than once.
Expected Behavior
{
"data"=>{
...
},
"included"=>
[
...
{
...
},
...
],l
"relationships"=> {
"c"=>{
data => {
...
}
}
}
},
"meta"=>{"total-count"=>1},
"links"=> {
"self"=> "http://link.com/path",
"current"=> "http://link.com/path",
}
Actual Behavior
{
"data"=>{
...
},
"included"=>
[
...
{
...
},
...
],l
"relationships"=> {
"c"=>{
data => {}
}
}
},
"meta"=>{"total-count"=>1},
"links"=> {
"self"=> "http://link.com/path",
"current"=> "http://link.com/path",
}
Specifications
- Version:
jsonapi ~> 1.7.0'
jsonapi-serializer ~> 2.2' - Ruby version: 3.0.5p211
- Rails version: 7.0.8
Metadata
Metadata
Assignees
Labels
No labels