Misc improvements to tests and query builder

* Automated storage tester: generate correct queries for FK equals
* IsEmpty checks should rely on super type instead of field type (in case of inheritance).