I think this patch fix the problem with foreign keys,
@beberlei, please take a look and tell me what you think about
Test Foreign Keys
group by all fields when entity has foreign keys
That was fast, thanks!
@FabioBatSilva: This patch broke PostgreSQL: http://travis-ci.org/#!/doctrine/doctrine2/builds/310593
I'm changing the test case