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

asDynamic() method for query results that can't be mapped to a model #21

Closed
wants to merge 2 commits into from
Closed

Conversation

nicjansma
Copy link
Contributor

Some query results can't (and shouldn't) be mapped back to one of the models. For example, when using a GROUP BY statement, if the SELECT has a COUNT(*) AS count result to get the grouping count:

In SQL:

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

In Joli, this doesn't work correctly:

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

Because the result is attempted to map to 'human', which the results are not.

I've added a .asDynamic() method that you would add before .execute(). If this is set, the results are retuned as a simple property bag instead of as a model.

The documentation was updated as well.

@divadrei
Copy link

divadrei commented Aug 6, 2012

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

@nicjansma
Copy link
Contributor Author

Ah, didn't notice that optional parameter. I'll close this and open a new pull request for a small documentation update.

@nicjansma nicjansma closed this Aug 7, 2012
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

2 participants