Merge pull request #816 from sgmap/avoid-loading-association

Avoid loading the association for the without_followers scope
This commit is contained in:
gregoirenovel 2017-10-17 14:16:52 +02:00 committed by GitHub
commit bd0f08cfd5
2 changed files with 8 additions and 1 deletions

View file

@ -60,7 +60,7 @@ class Dossier < ActiveRecord::Base
scope :termine, -> { not_archived.state_termine } scope :termine, -> { not_archived.state_termine }
scope :downloadable, -> { state_not_brouillon.includes(:entreprise, :etablissement, :champs, :champs_private) } scope :downloadable, -> { state_not_brouillon.includes(:entreprise, :etablissement, :champs, :champs_private) }
scope :en_cours, -> { not_archived.state_en_construction_ou_instruction } scope :en_cours, -> { not_archived.state_en_construction_ou_instruction }
scope :without_followers, -> { includes(:follows).where(follows: { id: nil }) } scope :without_followers, -> { left_outer_joins(:follows).where(follows: { id: nil }) }
scope :with_unread_notifications, -> { where(notifications: { already_read: false }) } scope :with_unread_notifications, -> { where(notifications: { already_read: false }) }
accepts_nested_attributes_for :individual accepts_nested_attributes_for :individual

View file

@ -3,6 +3,13 @@ require 'spec_helper'
describe Dossier do describe Dossier do
let(:user) { create(:user) } let(:user) { create(:user) }
describe "without_followers scope" do
let!(:dossier) { create(:dossier, :followed, :with_entreprise, user: user) }
let!(:dossier2) { create(:dossier, :with_entreprise, user: user) }
it { expect(Dossier.without_followers.to_a).to eq([dossier2]) }
end
describe 'methods' do describe 'methods' do
let(:dossier) { create(:dossier, :with_entreprise, user: user) } let(:dossier) { create(:dossier, :with_entreprise, user: user) }