Use instead of to enable join reuse
This commit is contained in:
@ -78,7 +78,7 @@ class StatisticsController < ApplicationController
|
||||
end
|
||||
|
||||
def statistics_last_login
|
||||
@members = current_organization.members.active.joins(:user).
|
||||
@members = current_organization.members.active.references(:user).
|
||||
order("users.current_sign_in_at ASC NULLS FIRST")
|
||||
end
|
||||
|
||||
@ -88,7 +88,7 @@ class StatisticsController < ApplicationController
|
||||
|
||||
def statistics_type_swaps
|
||||
offers = current_organization.posts.
|
||||
where(type: "Offer").joins(:transfers, transfers: :movements).
|
||||
where(type: "Offer").references(:transfers, transfers: :movements).
|
||||
select("posts.tags, posts.category_id, SUM(movements.amount) as
|
||||
sum_of_transfers, COUNT(transfers.id) as
|
||||
count_of_transfers").
|
||||
|
||||
@ -23,7 +23,7 @@ class Post < ActiveRecord::Base
|
||||
scope :by_organization, ->(org) { where(organization_id: org) if org }
|
||||
|
||||
scope :with_member, -> {
|
||||
joins(:organization, :user_members).
|
||||
references(:organization, :user_members).
|
||||
where("members.organization_id = posts.organization_id").
|
||||
select("posts.*, members.member_uid as member_id")
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@ class User < ActiveRecord::Base
|
||||
|
||||
default_scope -> { order("users.id ASC") }
|
||||
|
||||
scope :actives, -> { joins(:members).where(members: { active: true }) }
|
||||
scope :actives, -> { references(:members).where(members: { active: true }) }
|
||||
scope :online_active, -> { where("sign_in_count > 0") }
|
||||
scope :notifications, -> { where(notifications: true) }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user