Fix model query generation

Useful when we have several models in the same app and one of the
models has the same name as the app.