class ActiveFedora::Associations::ContainedFinder
Finds the objects which associate with a given record and are contained within the given container. Uses repository
to find the objects.
Attributes
container[R]
proxy_class[R]
repository[R]
Public Class Methods
new(container:, repository:, proxy_class:)
click to toggle source
@param [#contained_ids] container a container that records are stored
under.
@param [#translate_uri_to_id, find
] repository a repository to build
objects from.
@param [ActiveFedora::Base] proxy_class
class that represents an
ore:Proxy
# File lib/active_fedora/associations/contained_finder.rb, line 14 def initialize(container:, repository:, proxy_class:) @container = container @repository = repository @proxy_class = proxy_class end
Public Instance Methods
find(record)
click to toggle source
@param [ActiveFedora::Base] record a record which you want to find the
reference node for.
@return [Array<ActiveFedora::Base>] This returns whatever type
repository.find returns.
# File lib/active_fedora/associations/contained_finder.rb, line 24 def find(record) record.reload repository.find(matching_ids(record)) end
Private Instance Methods
matching_ids(record)
click to toggle source
# File lib/active_fedora/associations/contained_finder.rb, line 31 def matching_ids(record) IDComposite.new(proxy_ids(record) & contained_ids.to_a, repository.translate_uri_to_id) end
proxy_ids(record)
click to toggle source
# File lib/active_fedora/associations/contained_finder.rb, line 35 def proxy_ids(record) relation_subjects(record) end
relation_subjects(record)
click to toggle source
This could be done with Prefer InboundReferences, but that is a slow fedora call
# File lib/active_fedora/associations/contained_finder.rb, line 41 def relation_subjects(record) query = ActiveFedora::SolrQueryBuilder.construct_query_for_rel( [[:has_model, proxy_class.to_rdf_representation], [:proxyFor, record.id]] ) rows = ActiveFedora::SolrService::MAX_ROWS ActiveFedora::SolrService.query(query, fl: 'id', rows: rows).map(&:rdf_uri) end