Created
August 14, 2013 07:42
-
-
Save abhishek0/6228784 to your computer and use it in GitHub Desktop.
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
users = Arel::Table.new(:users) | |
stamps = Arel::Table.new(:stamps) | |
contacts = Arel::Table.new(:contacts) | |
children = users.alias | |
query = users.where(users[:user_type].eq('franchisee')) | |
query = query.join(stamps).on(users[:id].eq(stamps[:stampable_id])) | |
query = query.join(contacts).on(contacts[:id].eq(stamps[:contact_id])) | |
query = query.join(children).on(users[:id].eq(children[:parent_id])) | |
query = query.join(stamps).on(children[:id].eq(stamps[:stampable_id])) | |
query = query.group users[:id], stamps[:status] | |
query = query.project(users[:id], stamps[:status].count.as("count"), stamps[:status], contacts[:first_name], contacts[:last_name]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment