Skip to content

Instantly share code, notes, and snippets.

@elrayle
Last active November 27, 2017 19:36
Show Gist options
  • Save elrayle/26dfdf932f47f17131bae1c7bdbe1682 to your computer and use it in GitHub Desktop.
Save elrayle/26dfdf932f47f17131bae1c7bdbe1682 to your computer and use it in GitHub Desktop.

Setup

child_col1 = Collection.create(id: 'cc1', title: ['Child Collection 1'])
child_col2 = Collection.create(id: 'cc2', title: ['Child Collection 2'])
child_col3 = Collection.create(id: 'cc3', title: ['Child Collection 3'])
parent_col1 = Collection.create(id: 'pc1', title: ['Parent Collection 1'])
parent_col2 = Collection.create(id: 'pc2', title: ['Parent Collection 2'])
parent_col3 = Collection.create(id: 'pc3', title: ['Parent Collection 3'])
work1 = GenericWork.create(id: 'w1', title: ['Work 1'])
work2 = GenericWork.create(id: 'w2', title: ['Work 2'])
work3 = GenericWork.create(id: 'w3', title: ['Work 3'])

Nested Collections

Add collection to collection

REF: https://github.com/samvera/hyrax/blob/collections-sprint/app/controllers/hyrax/dashboard/nest_collections_controller.rb#L22-L39

child_col.member_of_collections [parent_col]

Get children collections

using active fedora REF: defined, but never used except in testing

parent_col.member_objects              # [child_col]
parent_col.member_object_ids           # ['cc1']

NOTE: If there are member works, they will be returned too.

using search builder

TBA

Get parent collections using active fedora

child_col.member_of_collections        # [parent_col]
child_col.member_of_collection_ids     # ['pc1']

Works in Collections

Add work to collection

REF: https://github.com/samvera/hyrax/blob/master/app/actors/hyrax/actors/collections_membership_actor.rb#L21-L28

work1.member_of_collections [col1, col2]

Get works in collection

parent1.member_object_ids                          # ['c1,'w1','w2']

Nested Works

Add work to work

REF: https://github.com/samvera/hyrax/blob/master/app/actors/hyrax/actors/add_to_work_actor.rb#L40-L50

parent_work1.ordered_members << child_work2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment