intridea/grape — pull request #400 by ejholmes (2013-05-02 07:20:05+00:00)
Title: Call to_ary on objects that respond to it, like ActiveRecord::Relations.

Currently, if you use `.present` with ActiveRecord, you will get double queries on collections, because `.first` [gets called](https://github.com/intridea/grape/blob/85c3424011fc6ec6d623895278d2808680f5491c/lib/grape/endpoint.rb#L311) on the ActiveRecord::Relation object, which triggers a `LIMIT 1` query.

This patch calls .to_ary on objects that respond to it, like ActiveRecord::Relations, converting it to any array before calling `.first` on it, which will prevent the additional query.

**Before**

```
SELECT "items".* FROM "items" LIMIT 1
SELECT "items".* FROM "items"
```

**After**

```
SELECT "items".* FROM "items"
```