Class: Bulkrax::Status
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Bulkrax::Status
- Defined in:
- app/models/bulkrax/status.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.latest_by_statusable_subtable ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'app/models/bulkrax/status.rb', line 14 def self.latest_by_statusable_subtable status_table = self.arel_table latest_status_query = status_table.project(status_table[:statusable_id], status_table[:statusable_type], status_table[:id].maximum.as("latest_status_id")).group(status_table[:statusable_id], status_table[:statusable_type]) latest_status_table = Arel::Table.new(latest_status_query).alias(:latest_status) status_table.join(latest_status_query.as(latest_status_table.name.to_s), Arel::Nodes::InnerJoin) .on(status_table[:id].eq(latest_status_table[:latest_status_id])) end |
Instance Method Details
#latest? ⇒ Boolean
25 26 27 28 29 30 31 32 |
# File 'app/models/bulkrax/status.rb', line 25 def latest? # TODO: remove if statment when we stop supporting Hyrax < 4 self.id == if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new('6.0.0') self.class.where(statusable_id: self.statusable_id, statusable_type: self.statusable_type).order('id desc').pick(:id) else self.class.where(statusable_id: self.statusable_id, statusable_type: self.statusable_type).order('id desc').pluck(:id).first # rubocop:disable Rails/Pick end end |