Sha256: 8fd15b74525a40c3de3aa6bdfb84e2e2ba48925dfe46f5763c14ac491c0d5b57

Contents?: true

Size: 711 Bytes

Versions: 20

Compression:

Stored size: 711 Bytes

Contents

module Ddr
  module Models
    module HasChildren
      extend ActiveSupport::Concern

      def first_child
        if datastreams.include?(Ddr::Datastreams::CONTENT_METADATA) && datastreams[Ddr::Datastreams::CONTENT_METADATA].has_content?
          first_child_pid = datastreams[Ddr::Datastreams::CONTENT_METADATA].first_pid
        else
          first_child_pid = ActiveFedora::SolrService.query(association_query(:children), rows: 1, sort: "#{Ddr::IndexFields::IDENTIFIER} ASC").first["id"]
        end      
        begin
          ActiveFedora::Base.find(first_child_pid, :cast => true) if first_child_pid
        rescue ActiveFedora::ObjectNotFound
          nil
        end
      end

    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ddr-models-1.11.8 lib/ddr/models/has_children.rb
ddr-models-1.11.7 lib/ddr/models/has_children.rb
ddr-models-1.11.6 lib/ddr/models/has_children.rb
ddr-models-1.11.5 lib/ddr/models/has_children.rb
ddr-models-1.11.4 lib/ddr/models/has_children.rb
ddr-models-1.11.3 lib/ddr/models/has_children.rb
ddr-models-1.11.2 lib/ddr/models/has_children.rb
ddr-models-1.11.1 lib/ddr/models/has_children.rb
ddr-models-1.11.0 lib/ddr/models/has_children.rb
ddr-models-1.10.0 lib/ddr/models/has_children.rb
ddr-models-1.9.0 lib/ddr/models/has_children.rb
ddr-models-1.8.1 lib/ddr/models/has_children.rb
ddr-models-1.8.0 lib/ddr/models/has_children.rb
ddr-models-1.7.0 lib/ddr/models/has_children.rb
ddr-models-1.6.0 lib/ddr/models/has_children.rb
ddr-models-1.5.0 lib/ddr/models/has_children.rb
ddr-models-1.4.0 lib/ddr/models/has_children.rb
ddr-models-1.3.0 lib/ddr/models/has_children.rb
ddr-models-1.2.1 lib/ddr/models/has_children.rb
ddr-models-1.2.0 lib/ddr/models/has_children.rb