How it Works: GenericFile and its files - mlibrary/hydra-prototype GitHub Wiki

Hydra::Works::GenericFile sets up

  included do
    directly_contains_one :original_file, through: :files, type: ::RDF::URI('http://pcdm.org/use#OriginalFile'), class_name: 'Hydra::PCDM::File'
    directly_contains_one :thumbnail, through: :files, type: ::RDF::URI('http://pcdm.org/use#ThumbnailImage'), class_name: 'Hydra::PCDM::File'
    directly_contains_one :extracted_text, through: :files, type: ::RDF::URI('http://pcdm.org/use#ExtractedText'), class_name: 'Hydra::PCDM::File'
  end

Uploading a file to a GenericFile instance using Hydra::Works::UploadFileToGenericFile (either deliberately or though the UI) causes:

Hydra::Works::AddFileToGenericFile.call(generic_file, file, :original_file, update_existing: update_existing, versioning: versioning)

which installs a pcdm:File object in the files container under the GenericFile instance; the instance gets a pcdm:hasFile relationship to the pcdm:File object.

This pcdm:File instance also gets a type of http://pcdm.org/use#OriginalFile.

The next time that gf.original_file is invoked, Hydra walks the pcdm:hasFile relationships to find the pcdm:File with the type of http://pcdm.org/use#OriginalFile.