her icon indicating copy to clipboard operation
her copied to clipboard

active_model_serializers format issue?

Open dvictory opened this issue 10 years ago • 5 comments

Perhaps I am misunderstanding the active_model_serializers format, but I have an issue when pulling down belongs to associations.

ex) I have a Post, which has Comments, and each comment belongs to a User. I don't have any nested objects returned from my api. When I do

class Post 
 include Her::Model
 has_many :comments
 parse_root_in_json true , format: :active_model_serializers
end

class Comment
include Her::Model
belongs_to :user
parse_root_in_json true , format: :active_model_serializers
end

class User
include Her::Model
parse_root_in_json true , format: :active_model_serializers
end

Post.all.each do |p|
  p.comments.each do |c|
    c.user.name
  end
end

it throws undefined method map' for nil:NilClass, on /lib/her/model/attributes.rb:35:ininitialize_collection'

From the code it appears it is looking for a collection rather than an object, but in this case we are returning the user object which looks like

{ "user": { "id": 1, "name": "Lindsay Fünke"} }

which is not an array. The offending line is in http.rb line 71

if parsed_data[:data].is_a?(Array) || active_model_serializers_format?

which tries to pull a collection from the belongs to association, which is obviously not an array.

Am I setting up the api incorrectly? Thanks

dvictory avatar Feb 05 '14 23:02 dvictory

any luck fixing this issue?

chrishough avatar Apr 17 '14 19:04 chrishough

I am also seeing this issue :(

ashmckenzie avatar Jun 26 '14 10:06 ashmckenzie

Hey guys i've got this issue as well any eta on when the fix will be merged in?

djh3315 avatar Aug 25 '14 12:08 djh3315

This is still a critical bug that we need fixed. Is there a workaround for this that I am missing?

djh3315 avatar Sep 15 '14 14:09 djh3315

I just bumped into this bug.

benwoodward avatar Jul 30 '15 22:07 benwoodward