Method: Valkyrie::Persistence::Fedora::QueryService#find_inverse_references_by
- Defined in:
- lib/valkyrie/persistence/fedora/query_service.rb
#find_inverse_references_by(resource: nil, id: nil, property:, model: nil) ⇒ Array<Valkyrie::Resource>
Get all resources which link to a resource with a given property. Find all resources referencing a given resource (e. g. parents) *This is done by iterating through the ID of each resource referencing the resource in the query, and requesting each resource over the HTTP* *Also, an initial request is made to find the URIs of the resources referencing the resource in the query*
119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/valkyrie/persistence/fedora/query_service.rb', line 119 def find_inverse_references_by(resource: nil, id: nil, property:, model: nil) raise ArgumentError, "Provide resource or id" unless resource || id ensure_persisted(resource) if resource resource ||= find_by(id: id) ids = find_inverse_reference_ids_by_unordered(resource: resource, property: property).uniq objects_from_unordered = ids.lazy.map { |ref_id| find_by(id: ref_id) } objects_from_ordered = find_inverse_references_by_ordered(resource: resource, property: property, ignore_ids: ids) objects = [objects_from_unordered, objects_from_ordered].lazy.flat_map(&:lazy) return objects unless model objects.select { |obj| obj.is_a?(model) } end |