Guest User

Untitled

a guest
Oct 15th, 2024
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.73 KB | None | 0 0
  1. # Step 1: Define the base interaction query, potentially with filtering via ransack
  2. interactions_query = Interaction.ransack(interactions_event_query).result
  3.  
  4. # Step 2: Join employees and group by interaction_type and compare_key to get total counts
  5. total_interactions = interactions_query
  6.   .joins(:employee)  # Simplified as a normal join now
  7.   .group('interaction_type', "employees.#{compare_key}")
  8.   .count
  9.  
  10. # Step 3: For unique interactions, we use ActiveRecord's distinct method and the same grouping
  11. unique_interactions = interactions_query
  12.   .select('distinct interaction_type, employee_id')  # Unique interactions based on type and employee
  13.   .joins(:employee)
  14.   .group('interaction_type', "employees.#{compare_key}")
  15.   .count
  16.  
Advertisement
Add Comment
Please, Sign In to add comment