Sitelet https://github.com/jsonapi-serializer/jsonapi-serializer/issues/241
Skip to content

Relation attributes are not being serialized in this gem #241

Description

@Victorcorcos

The Issue

I noticed that the item relation attributes are not being serialized in this gem, just the :id and :type keys are being serialized for the relations. Take in mind that I'm talking about the item's relation(s), not about the item itself that is being serialized.

How can we serialize the attributes of the item relations in this gem?
Is there an option for that already?

  • Setup:
# .../app/serializers/attachment_serializer.rb
class AttachmentSerializer
  include JSONAPI::Serializer

  attributes :id, :name

  belongs_to :project
end
# .../app/serializers/project_serializer.rb
class ProjectSerializer
  include JSONAPI::Serializer

  attributes :id, :name, :active

  has_many :users
end
  • How to Reproduce
attachment = Attachment.last
AttachmentSerializer.new(attachment).serializable_hash

⚠️ this is not displaying either project's name and active attributes after the serialization.

Expected Behavior

{:id=>"637cf4d769ca9c09a5f6a0d8",
 :type=>:attachment,
 :attributes=>
  {:id=>BSON::ObjectId('637cf4d769ca9c09a5f6a0d8'),
   :name=>"PostMan Tutorial",},
 :relationships=>
  {:project=>{:data=>{:id=>BSON::ObjectId('641d2f6c69ca9c0f54edfb10'),
                      :name=>"Project with Sheet View",
                      :active=>true}}

Actual Behavior

{:id=>"637cf4d769ca9c09a5f6a0d8",
 :type=>:attachment,
 :attributes=>
  {:id=>BSON::ObjectId('637cf4d769ca9c09a5f6a0d8'),
   :name=>"PostMan Tutorial",},
 :relationships=>
  {:project=>{:data=>{:id=>"62ed6a75a6af03010ff96521"}}

Specifications

  • Version: 2.2.0
  • Ruby version: 3.2.2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions