Tuning of scopes and class methods to support postgresql