-
Notifications
You must be signed in to change notification settings - Fork 89
Open
Description
Hello,
following test code illustrates the behaviour:
class Post
attr_accessor :id, :title, :content, :likes
def initialize(params)
@id = params[:id]
@title = params[:title]
@content = params[:content]
@likes = params[:likes]
end
def likes
puts "likes called" # getter gets called twice.
@likes
end
endclass Like
attr_accessor :id, :content
def initialize(params)
@id = params[:id]
@content = params[:content]
end
endrequire 'jsonapi-serializers'
class PostSerializer
include JSONAPI::Serializer
attribute :title
attribute :content
has_many :likes, include_data: false
end
class LikeSerializer
include JSONAPI::Serializer
attribute :content
endpost = Post.new({
id: 1,
title: 'title',
content: 'content',
likes: [
Like.new(id: 2, content: 'test'),
Like.new(id: 3, content: 'test2')
]
})
JSONAPI::Serializer.serialize(post, is_collection: false, include: ['likes'])Is this the expected behaviour? Maybe an if-statement? I did not look deep in code yet.
Our problem is, that we have some time-consuming "getter"-functions and don't want to use/aren't able to use members.
Best regards!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels