-
Notifications
You must be signed in to change notification settings - Fork 152
Kernel methods get priority over delegate methods #215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've ran into the same problem before, and the way that I handled it was class Foo < ActiveRecord::Base
belongs_to :system
class Entity < Grape::Entity
expose :system do |foo, options|
foo.system
end
end
end It's not great, but it works. |
Is there something we can do about this in grape-entity? |
Sure, setting this to You could also just exclude methods not owned by the entity class, á la
|
@Linell Thanks, that would work. Unfortunately, we actually do not have the Entity classes in the model classes themselves (gave that example for simplicity), so we usually have something like
|
This patch prevents Entity from delegating attributes to Kernel methods. This is accomplished by testing the methods the Entity class responds to for ownership by the Entity class itself. Fixes ruby-grape#215.
Hi,
Question: Due to the way exposures are looked up in the entity class first (calling
respond_to attribute, true
), attributes defined on the delegate class that collide withKernel
methods can not be exposed. We today noticed that with a AR model that has abelongs_to :system
association. Probably poor wording on our side, but still: What would be the preferred way to deal with this? Currently we need to monkey-patchGrape::Entity#delegate_attribute
.Thanks,
Malte
The text was updated successfully, but these errors were encountered: