I have churches who use the song.
With a specific song id I am trying to get the most recent use date and the total usage of the churches limited by the user.
@usages = use.select ("MAX (services.date) as date") ,: song_name ,: song_id, "count_song_id" as song_id). Joins (: service, song). The code above is working (where:: Services = & gt; {church_id: current_user.church_id}) group (: song_name ,: song_id) .order ("count_song_id DESC")
But now I have started implementing the Pandit Authority and have participated in some difficulties. My prospecting policy is very simple:
class scope of the class & lt; If the area of user.admin is fixed? Scope.all other scope.where church_id: current_user.church_id end and end
The problem is how to actually use it. It does not seem right, but I am in any kind of loss:
@usages = policy_scope Usage.select ("MAX (services.date) date as") ,: song_name ,: song_id , Count_song_id as "count_song_id"). Joins (: service, song) .group (: song_name ,: song_id) .order ("count_song_id DESC")
So what is finished (I think):
@usages = policy_scope (use. Joins: service). Selection ("MAX (services.date)" as the date,: song_name ,: song_id, "count_song_id count (song_id)") .Jom ((service:, song) .group (: song_name ,: song_id) . Command ("count_song_id DESC")
key policy_scope (use. Joins: service)
No comments:
Post a Comment