Query proxy refactor

Support http://guides.rubyonrails.org/active_record_querying.html#scopes, issue #444