how do I create isMemberOf relationships between objects?

62 views
Skip to first unread message

Bess Sadler

unread,
Aug 30, 2011, 8:13:12 PM8/30/11
to active...@googlegroups.com

I want to create an "isMemberOf" relationship between two objects. I'm using ActiveFedora 2.3.3 on ree 1.8.7. I'm getting the impression that this isn't possible and that I need to be working with ActiveFedora trunk in order to do this. Is that right?

Thanks!

Bess

Rick Johnson

unread,
Aug 31, 2011, 9:04:57 AM8/31/11
to active...@googlegroups.com, bess....@gmail.com
Hi Bess,

  The ActiveFedora version you have should be fine.  You should just need to have relationships defined within the ActiveFedora models you are using that reference isMemberOf.  It would be something like:

class MyAFClass1 < ActiveFedora::Base
    has_relationship "member_of", :is_member_of
end

class MyAFClass2 < ActiveFedora::Base
    has_relationship "members", :is_member_of, :inbound => true
end

Then you would be able to assert the relationship like:

obj1 = MyAFClass1.new
obj2 = MyAFClass2.new
obj1.member_of_append(obj2)
obj1.save

There are a few other ways to define the relationships depending on whether you want to assert the relationship from the child or from the parent (or both).  The above example assumes the child maintains the relationship and therefore the parent becomes aware of the relationship via an "inbound" relationship.  All that means is that when initializing its list of members objects it queries solr for any objects that assert a relationship of "is_member_of_s:info:fedora/[obj2.pid]".

Hopefully that is what you were looking for, but let me know if there are follow-up questions...

Rick




--
You received this message because you are subscribed to the Google Groups "ActiveFedora / Ruby + Fedora Commons" group.
To post to this group, send email to active...@googlegroups.com.
To unsubscribe from this group, send email to active-fedor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/active-fedora?hl=en.


Bess Sadler

unread,
Aug 31, 2011, 5:24:46 PM8/31/11
to active...@googlegroups.com
Thanks for your reply, Rick. 

I took another swing at it and figured out what I was trying to do. I'm not working in a rails context, I'm creating some bulk object creation scripts for the hypatia project. Here's what I was trying to do. I don't know why it wouldn't work for me last night, but now it seems to be working fine. 

foo = ActiveFedora::Base.new
bar = ActiveFedora::Base.new
bar.add_relationship("isMemberOf",foo)
 => true 
bar.relationships
 => {:self=>{"isMemberOf"=>["info:fedora/changeme:21"]}} 

Cheers, 
Bess

Bess Sadler

unread,
Aug 31, 2011, 6:07:01 PM8/31/11
to active...@googlegroups.com
Please disregard my last message. Rick, you were exactly right, subclassing ActiveFedora::Base and declaring those relationships in the class isn't optional. Here's what I ended up with:

class HypatiaFile < ActiveFedora::Base
  has_relationship "member_of", :is_member_of
end

class HypatiaItem < ActiveFedora::Base
  has_relationship "members", :is_member_of, :inbound => true
end

    hypatia_item = HypatiaItem.new
    hypatia_file = HypatiaFile.new

    hypatia_file.add_relationship(:is_member_of,hypatia_item)
    hypatia_item.inbound_relationships
=> {:is_member_of=>["info:fedora/changeme:54"]}

Thanks to Rick and jcoyne on #projecthydra for the help!

Bess


On Aug 31, 2011, at 6:04 AM, Rick Johnson wrote:

Reply all
Reply to author
Forward
0 new messages