curationexperts / tufts_models

Hydra models for Tufts
0 stars 3 forks source link

collection.member_ids is inconsistent #8

Open bmaddy opened 9 years ago

bmaddy commented 9 years ago

The value of .member_ids changes when .members is called for collections that have members who have been deleted.

c = ActiveFedora::Base.find('tufts.uc:6')
 => #<PersonalCollection pid: "tufts.uc:6", creator: "brian+admin@brianmaddy.com", description: [""], date_created: [], title: "Good lookin'", createdby: "tdil", displays: ["tdil"]> 
c.member_ids.map(&:to_s)
 => ["changeme:2972", "tufts:1", "changeme:2971", "changeme:2973", "tufts:3", "changeme:2972", "tufts:1"] 
c.members.map(&:pid)
 => ["changeme:2972", "changeme:2971", "changeme:2973", "tufts:3", "changeme:2972"] 
c.member_ids.map(&:to_s)
 => ["changeme:2972", "changeme:2971", "changeme:2973", "tufts:3", "changeme:2972"] 

@jcoyne, would it be a problem to do a .map{|pid| ActiveFedora::Base.exists?(pid)} over the member_ids? We could also make a new attribute .raw_member_ids that contains the deleted pids.

jcoyne commented 9 years ago

I think member_ids should always show the actual recorded member_ids. If you want to filter on those that exist, make a new method that is member_ids_that_exist

bmaddy commented 9 years ago

This happens because remove_missing_members gets called by members. A potential solution is to make these methods: member_ids: returns the member ids from the collection member_ids_that_exist: returns all member_ids and filters out any that don't exist members: returns member models with nils for ones that have been deleted members_that_exist: returns only members that have not been deleted