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

embedded relationship data does not honor relationship's object_method_name #64

Description

@waymondo

Expected Behavior vs Actual Behavior

When using has_many, I would expect both the included, related objects and the source object's relationship data to use the same specified object_method_name, however only the "included" objects seem to use the method. Using the block definition for has_many works as I would expect.

Steps to Reproduce the Problem

class Location < ApplicationRecord
  has_many :deals
  has_many :active_deals, -> { where(active: true) }, source: :deals
end

class LocationSerializer
  include FastJsonapi::ObjectSerializer
  has_many :deals, object_method_name: :active_deals
end

# create 1 deal for the location with active as false

pp LocationSerializer.new(@location).to_json

{"data"=>
  [{"id"=>"xxx",
    "type"=>"location",
    "attributes"=>
     {},
    "relationships"=>
     {"deals"=>{"data"=>[{"id"=>"xxx", "type"=>"deal"}]}}}],
 "included"=>[]}

The 'inactive' deal is included in the location's relationship data.

Specifications

  • Version: 1.6.0
  • Ruby version: 2.6.5

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions