Fix commodity ancestor selection

This change is a fix for https://www.pivotaltracker.com/story/show/52133375

We had one too many commodites in the tree on the commodity show page. The reason behind a bug is mainly how MySQL order and group by works (http://blog.chomperstomp.com/how-to-order-by-before-group-by-with-mysql/), i.e. they should happen in separate queries.