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

endpoint#present makes needless sql query #632

Closed
wants to merge 3 commits into from

Conversation

fixme
Copy link
Contributor

@fixme fixme commented Apr 18, 2014

Hey, here is some fix to prevent needless sql query in endpoint#present method, because of #first method usage on activerecord relations.
Example:

author = Author.find params[:id]
present author.books

it makes an additional sql query on books relation because of #first method usage in entity's auto-detection block.

@dblock
Copy link
Member

dblock commented Apr 19, 2014

So who defines klass? Is this some kind of standard in ActiveRecord? Any other ODM/ORM doing that? Otherwise this looks good. Can you please update CHANGELOG? Thx.

@fixme
Copy link
Contributor Author

fixme commented Apr 21, 2014

Yes, it's standard method of ActiveRecord relations, it returns the relation's model and it's very useful in case of lazy loading. No, unfortunately it works only with ActiveRecord. No problem.

@@ -13,6 +13,7 @@ Next Release
* [#614](https://github.com/intridea/grape/pull/614): Params with `nil` value are now refused by `RegexpValidator` - [@dm1try](https://github.com/dm1try).
* [#494](https://github.com/intridea/grape/issues/494): Fixed performance issue with requests carrying a large payload - [@dblock](https://github.com/dblock).
* [#619](https://github.com/intridea/grape/pull/619): Convert specs to RSpec 3 syntax with Transpec - [@danielspector](https://github.com/danielspector).
* [#632](https://github.com/intridea/grape/pull/632): Usage of Grape::Endpoint#present for ActiveRecord relations doesn't make an additional query during entity's detection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fixme , please mention yourself :)
... during entity's detection - [@fixme](https://github.com/fixme).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've forgot :)

@dblock
Copy link
Member

dblock commented Apr 21, 2014

Merged via 597fabf, thank you!

@dblock dblock closed this Apr 21, 2014
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.

None yet

3 participants