tests, Orm and query bug fixes