Sha256: 87af02b16e4b03263c1c384aa2c4f8805150423468eec4abeb3bd835eeb79337

Contents?: true

Size: 640 Bytes

Versions: 3

Compression:

Stored size: 640 Bytes

Contents

# frozen_string_literal: true
module Hyrax
  ##
  # A module of form behaviours for resources which can be contained in works.
  module ContainedInWorksBehavior
    ##
    # @api private
    InWorksPrepopulator = proc do |_options|
      self.in_works_ids =
        if persisted?
          Hyrax.query_service
               .find_inverse_references_by(resource: model, property: :member_ids)
               .select(&:work?)
               .map(&:id)
        else
          []
        end
    end

    def self.included(descendant)
      descendant.property :in_works_ids, virtual: true, prepopulator: InWorksPrepopulator
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/forms/concerns/hyrax/contained_in_works_behavior.rb
hyrax-5.0.0 app/forms/concerns/hyrax/contained_in_works_behavior.rb
hyrax-5.0.0.rc3 app/forms/concerns/hyrax/contained_in_works_behavior.rb