Use instead of to enable join reuse

This commit is contained in:
Saverio Trioni
2015-05-06 17:51:35 +02:00
parent de367d5a52
commit d594d5759e
3 changed files with 4 additions and 4 deletions

View File

@ -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").

View File

@ -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")
}

View File

@ -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) }