Subquerying RealmResults

Issue #594 reports a wrong cast. The cast is wrong in the case where a `RealmResults` is queried using `where()`. This PR fixes the bug and adds unit tests to both plain queries and link queries.

@bmunkholm @cmelchior @emanuelez 
reword "subquerying" - what is that? (yes I know, but others..)