-
Notifications
You must be signed in to change notification settings - Fork 152
Open
Description
When you have an entity which exposes an ActiveRecord belongs_to
without a :using
option, then serializable_hash
is called with a Grape::Entity::Options
object.
But serializable_hash clones the object and then tries to set :except
on it. (It sets default :except
to an empty array see here.) This causes the exception:
NoMethodError: undefined method '[]=' for #<Grape::Entity::Options:0x007fc6a6f1a7b0>
Not too big of a problem, it was just a forgotten :using
, but it was very confusing.
Also depending on whether it's an object, array or hash, serializable_hash
is called with or without options.
I'm talking about the code in Grape::Entity::Exposure::Base#serializable_value.
Should the options even be passed to serializable_hash
at all? Or should []=
be implemented?
This did work up until this commit btw.
Example to reproduce:
class Author < ActiveRecord::Base
end
class Post < ActiveRecord::Base
belongs_to :author
end
class PostEntity < Grape::Entity
expose :author # notice missing :using
end
PostEntity.represent(Post.first).as_json # => NoMethodError