Skip to content

Commit

Permalink
Documentation update with an example for .execute('array')
Browse files Browse the repository at this point in the history
  • Loading branch information
nicjansma committed Aug 7, 2012
1 parent 74496d2 commit 3fe97a2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.markdown
Expand Up @@ -239,6 +239,24 @@ In some cases however, you will find this way of querying your models just too l
order: ['last_name desc', 'first_name asc']
});

### Data retrieval for queries with no specific model (eg, GROUP BY)

Some query results can't be mapped back to a Joli model. For example, when using a `GROUP BY` statement:

SELECT city, COUNT(*) as count
FROM human
GROUP BY city

The rows returned by the above query are not Joli models, but simple `[city, count]` tuples.

To avoid having Joli try to map the query results to a model, you can pass a string parameter `"array"` to the
`.execute()` function to have the results returned as an array of simple objects:

var q = new joli.query()
.select('city, COUNT(*) as count')
.from('human')
.groupBy('city')
.execute("array");

## Internals
joli.js is made of several classes:
Expand Down

0 comments on commit 3fe97a2

Please sign in to comment.