Closed uhrohraggy closed 7 years ago
present?
is a Rails construct, not available to us here. A fix for this could be:
data['id'] = serializer.id.to_s if serializer.id && !serializer.id.to_s.empty?
thanks @fotinakis for the clarification! I thought my assumptions were off... I agree, I think that would solve it, and can't think of a case where that would lead to false positives.
For now, I fixed it by calling to_s in the method definition that overrode id. thanks again!
Regarding https://github.com/fotinakis/jsonapi-serializers/blob/master/lib/jsonapi-serializers/serializer.rb#L413
if you override and pass a numeric id to the serializer, it fails on the ! empty? "undefined method `empty?' for 1234:Fixnum"
I think it should be written simply as:
data['id'] = serializer.id.to_s if serializer.id.present?
I bring it up as an issue in case I don't fully understand the context of why it was checked against
!serializer.id.empty?