Added eager loading

This commit is contained in:
2024-08-04 21:33:30 +02:00
parent 3e0a5bbaea
commit acc5790663

View File

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