Skip to content
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

Fixed model inclusion in models with aliased references #135

Closed
wants to merge 2 commits into from

Conversation

cdarne
Copy link
Contributor

@cdarne cdarne commented Aug 1, 2014

If an entity has a field with an alias and it references another entity, the latter won't be included in the model's list.

Entity example:

class AliasedThing < Grape::Entity
  expose :something, as: :post, # the field is aliased
  using: Something, # and it references another entity
  documentation: { type: 'Something', desc: 'Reference to something.' }
end

The doc generated for an action using this entity will include the AliasedThing model but not the Something model.

That's because when the models_with_included_presenters method fails to match aliased fields. When it's looking in each models, it tries to match fields from model.exposure and model.documentation. But model.exposure returns the primary name as key, and model.documentation returns the aliased name as key. That's why they don't match.

Here's my proposition for a fix. It's also a refactoring; I think it would be simpler to iterate just model.exposure and check for a :documentation key.

@dblock
Copy link
Member

dblock commented Aug 1, 2014

Thanks this is great. Merged via tim-vandecasteele@30e8c92.

@dblock dblock closed this Aug 1, 2014
@cdarne cdarne deleted the fix-model-alias-ref branch August 1, 2014 12:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants