0

I had rails 4.2 and ruby 2.3.5 and I'm upgrading it to rails 5.2 with ruby 2.6.1.

With older rails version(4.2) my UserAuthenticatedSerializer is working fine and was giving a proper response.

After upgrading to rails 5.2 my Serializer started throwing an argument error.

I debugged it and it's throwing from relationship.rb file method name fetch_id and fetch_associated_object Here in both methods, object_block.call(record, params) throwing an argument error.

If I remove the second parameter from the params it works fine. Passing these two arguments causes an error.

This same association work with rails 4.2 but it's not working in rails 5.2.

Here is my code snap :

response = UserAuthenticatedSerializer.new(@user, { params: { domain: current_domain } }).to_json
error = ArgumentError (wrong number of arguments (given 1, expected 0))

user_authenticated_serializer.rb ===>
class UserAuthenticatedSerializer
include FastJsonapi::ObjectSerializer
has_one :user_profile, serializer: UserProfileSerializer, &:user_profile
has_many :user_topic_label_order, &:user_topic_label_order
end

user.rb ====>
Relationship in user model:
has_one :user_profile, dependent: :destroy
has_many :user_topic_label_order, dependent: :destroy

Rails version : 5.2.2 Ruby version : ruby 2.6.1 fast_jsonapi gem version : fast_jsonapi (1.5) active_model_serializers (~> 0.10.9)

Egon Allison
  • 1,329
  • 1
  • 13
  • 22
  • I have created a working demo to reproduce issue for our fast-json serializer 1) Here is app https://github.com/mayankkumarji/fast-json-demo 2) Setup Instruction link and issue reproduce https://github.com/mayankkumarji/fast-json-demo/wiki/Setup-Instruction – Nitesh Choudhary Apr 03 '19 at 13:15

1 Answers1

0

The error comes from your serializer, namely from passing an extra argument to has_one. Try this instead:

class UserAuthenticatedSerializer
  include FastJsonapi::ObjectSerializer
  attributes :name, :address

  has_one :user_profile #, &:user_profile
end

You don't need to pass in anything extra.

Jan Klimo
  • 4,643
  • 2
  • 36
  • 42