-
Notifications
You must be signed in to change notification settings - Fork 124
Relationships Development Pattern
E. Lynette Rayle edited this page Feb 4, 2022
·
8 revisions
NOTE: At this writing, all links are to code in Release 3.3.0.
NOTE: This is a developer oriented document. As such, it only describes how to maintain relationships in code.
The relationships:
- A Collection MAY be in one or more Collections (NOTE: The collection type of both MUST support nesting.)
- A Work MUST be in one and only one Admin Set (NOTE: This is a special type of Collection requiring Work membership.)
- A Work MAY be in one or more Collections (NOTE: Some collection types require a Work, if it is in a Collection of that type, to be in one and only one Collection of that type.)
- A Work, if it is in another work, MUST be in one and only one other Work
- A File Set, if a work has a file, MUST be in one and only one Work
- A File Set MUST contain one uploaded File and MAY contain multiple derivatives of that File
Admin Set:
- has no direct knowledge of works
- must search for the works using the inverse relationship
The following will find works in the admin set:
work_ids = Hyrax.query_service.find_inverse_references_by(resource: admin_set, property: admin_set_id).map(&:id)
works = Hyrax.query_service.find_inverse_references_by(resource: admin_set, property: admin_set_id)
Works: have a direct link to the admin set in attribute: :admin_set_id
The following will find a work's admin set:
admin_set_id = work.admin_set_id
admin_set = Hyrax.query_service.find_by(id: work.admin_set_id)
Parent Collection:
- has no direct knowledge of children
- must search for the children using the inverse relationship
The following will find child-collections:
child_collection_ids = Hyrax.custom_queries.find_child_collection_ids(resource: parent_collection)
child_collections = Hyrax.custom_queries.find_child_collections(resource: parent_collection)
Children: have direct link to parent(s) in attribute: :member_of_collection_ids
The following will find parent-collections:
parent_collection_ids = Hyrax.custom_queries.find_parent_collection_ids(resource: child_collection)
parent_collections = Hyrax.custom_queries.find_parent_collections(resource: child_collection)
When work is_a Hyrax::Work which is_a Valkyrie::Resource
work_resource.admin_set_id = admin_set_resource.id
work_resource = Hyrax.persister.save(resource: work_resource)
NOTE: The work will no longer be in the old Admin Set since it can belong to one and only one Admin Set.