Skip to content

Instantly share code, notes, and snippets.

@awead
Last active December 15, 2015 17:20
Show Gist options
  • Save awead/5296086 to your computer and use it in GitHub Desktop.
Save awead/5296086 to your computer and use it in GitHub Desktop.
NB: A collection has many series, a series is part of one collection.
This doesn't work. After reloding the collection, it still has the same number of series:
> c = ArchivalCollection.find("arc:test")
=> #<ArchivalCollection pid:"arc:test", title:"Test Collection", format:"Collection">
> c.series.count
=> 3
> c.series.pop
=> #<ArchivalComponent pid:"arc:testref3", title:"Series 1: Sample Series">
> c.save
=> true
> c.series.count
=> 2
> c = ArchivalCollection.find("arc:test")
=> #<ArchivalCollection pid:"arc:test", title:"Test Collection", format:"Collection">
> c.series.count
=> 3
This works by setting the parent collection to nil on the series (child).
Here, I just arbitrarily delete the last series object from the collection:
> c = ArchivalCollection.find("arc:test")
=> #<ArchivalCollection pid:"arc:test", title:"Test Collection", format:"Collection">
> c.series.count
=> 3
> c.series.last.collection = nil
=> nil
> c.series.last.save
=> true
> c.save
=> true
> c = ArchivalCollection.find("arc:test")
=> #<ArchivalCollection pid:"arc:test", title:"Test Collection", format:"Collection">
> c.series.count
=> 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment