Created
August 29, 2012 08:10
-
-
Save donovan-duplessis/3508355 to your computer and use it in GitHub Desktop.
Consultant Reports query within model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.reports(current_user) | |
select_fields = %w[ | |
consultant_reports.id consultant_reports.week | |
teams.id teams.name admin_users.id admin_users.name | |
] | |
group_fields = %w[ teams.name admin_users.name consultant_reports.week ] | |
data = joins(:team, :admin_user).select(select_fields).group(group_fields) | |
current_user.has_role?(:consultant) ? | |
data.where('teams.admin_user_id = ?', current_user.id) : data | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment