Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # add this to /config/initializers/global_named_scopes.rb
- class ActiveRecord::Base
- named_scope :conditions, lambda { |*args| { :conditions => args} }
- end
- scope = ProjectTotalView.scoped({})
- unless @current_user.has_access_to_all_projects?
- scope = scope.scoped({
- :joins => 'INNER JOIN project_people_access_vw s ON (
- s.fin_project_id = project_totals_vw.fin_project_id AND
- s.cost_centre_code = project_totals_vw.cost_centre_code)',
- :conditions => ['s.person_id = ? and s.access_type = ?', @current_user.emplid, ProjectAccess::ACCESS_STD]
- })
- end
- #Only this years projects
- scope = scope.conditions 'year = ? ', Time.now.strftime('%Y')
- # Only Active projects by default
- scope = scope.conditions "project_status_code = 'A'" unless ns['closed']
- # only Active Cost Centres by default
- scope = scope.conditions "cost_centre_status_code = 'A'" unless ns['closed_cost_centres']
- scope = scope.scoped({:select => 'bla', :joins => {:abc}, :order => 'abc desc'}
Add Comment
Please, Sign In to add comment