From acc5790663c87a896eb32040130d9c5d4d3057a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20B=C3=B6hm?= Date: Sun, 4 Aug 2024 21:33:30 +0200 Subject: [PATCH] Added eager loading --- app/models/job.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/job.rb b/app/models/job.rb index 6bf24b7..25b786a 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -2,7 +2,7 @@ class Job < ApplicationRecord belongs_to :operator, class_name: 'User', optional: true belongs_to :costumer, class_name: 'User', optional: true - has_one_attached :pdf + has_one_attached :pdf, dependent: :destroy validates_presence_of :costumer_firstname, :costumer_lastname, :privacy_policy_accepted, :pdf validate :acceptable_pdf @@ -32,7 +32,7 @@ class Job < ApplicationRecord where('upgraded_at >= ? AND upgraded_at <= ?', date.beginning_of_day, date.end_of_day) } # Returns all jobs with status: open print ready_for_pickup and jobs from today with status: paid canceled - # paid: only printed_at today + # paid: only updated_at today # canceled: only updated_at today def self.currently_working_on # NOTE: use Time.now instead of Date.today to take the timezone into account @@ -42,6 +42,8 @@ class Job < ApplicationRecord # .in_status_order .order(created_at: :desc) .order(:costumer_firstname, :costumer_lastname) + .with_attached_pdf # scope from activestorage for .includes(pdf_attachment: :blob) + # .references(:pdf_attachment, :blob) # creates big join table end def fullname