her
her copied to clipboard
active_model_serializers format issue?
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:in
initialize_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
any luck fixing this issue?
I am also seeing this issue :(
Hey guys i've got this issue as well any eta on when the fix will be merged in?
This is still a critical bug that we need fixed. Is there a workaround for this that I am missing?
I just bumped into this bug.