removing relationships

7 views
Skip to first unread message

adam wead

unread,
Aug 4, 2010, 9:25:41 AM8/4/10
to ActiveFedora / Ruby + Fedora Commons
Hi Matt,

Is there the equivalent of a delete_relationship method for AF
objects? I'm trying to update the RELS-EXT datastream of a parent
object by removing a particular pid from the has_member
relationship.

thanks,

...adam

Rick Johnson

unread,
Aug 4, 2010, 11:40:58 AM8/4/10
to active...@googlegroups.com
Hi Adam and Matt,

 This is actually included in some code I am about to submit for update to ActiveFedora.  I suggest putting the current code into a module for the time being and then including it in your model classes:

def remove_relationship(predicate, object)
        unregister_triple(:self, predicate, object)
    end

    def unregister_triple(subject, predicate, object)
      if relationship_exists?(subject, predicate, object)
        r = ActiveFedora::Relationship.new(:subject=>subject, :predicate=>predicate, :object=>object)
        relationships[subject][predicate].delete_if {|curObj| curObj == r.object}
        relationships[subject].delete(predicate) if relationships[subject][predicate].nil? || relationships[subject][predicate].empty?
        rels_ext.dirty = true
      else
        return false
      end    
    end


--
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.


Rick Johnson

unread,
Aug 4, 2010, 1:29:31 PM8/4/10
to active...@googlegroups.com
Realized that there is one more method being called that I added that should be included as well:

def relationship_exists?(subject, predicate, object)

     r = ActiveFedora::Relationship.new(:subject=>subject, :predicate=>predicate, :object=>object)
     relationships.has_key?(subject)&&relationships[subject].has_key?(predicate)&&relationships[subject][predicate].include?(r.object)
   end

adam wead

unread,
Aug 4, 2010, 1:35:51 PM8/4/10
to ActiveFedora / Ruby + Fedora Commons
Thanks, Rick...

I'm trying it out and don't appear to the have relationship_exists?
method. I placed the code in one of my models. Also, does the object
have to exist in Fedora? Not a big deal if it has to, it'll mean
deleting the relationship before deleting the object. So,

object = AfModel.load_instance("[pid]")
parent = AfModel.load_instance("[parent_pid"])
parent.remove_relationship(:has_memeber, object)

...adam

On Aug 4, 11:40 am, Rick Johnson <richardpatrickjohn...@gmail.com>
wrote:
> Hi Adam and Matt,
>
>  This is actually included in some code I am about to submit for update to
> ActiveFedora.  I suggest putting the current code into a module for the time
> being and then including it in your model classes:
>
> def remove_relationship(predicate, object)
>         unregister_triple(:self, predicate, object)
>     end
>
>     def unregister_triple(subject, predicate, object)
>       if relationship_exists?(subject, predicate, object)
>         r = ActiveFedora::Relationship.new(:subject=>subject,
> :predicate=>predicate, :object=>object)
>         relationships[subject][predicate].delete_if {|curObj| curObj ==
> r.object}
>         relationships[subject].delete(predicate) if
> relationships[subject][predicate].nil? ||
> relationships[subject][predicate].empty?
>         rels_ext.dirty = true
>       else
>         return false
>       end
>     end
>
> On Wed, Aug 4, 2010 at 9:25 AM, adam wead <amsterda...@gmail.com> wrote:
> > Hi Matt,
>
> > Is there the equivalent of a delete_relationship method for AF
> > objects?  I'm trying to update the RELS-EXT datastream of a parent
> > object by removing a particular pid from the has_member
> > relationship.
>
> > thanks,
>
> > ...adam
>
> > --
> > 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<active-fedora%2Bunsu...@googlegroups.com>
> > .

adam wead

unread,
Aug 4, 2010, 1:36:36 PM8/4/10
to ActiveFedora / Ruby + Fedora Commons
ha! beat you to it! :)

thanks...

adam wead

unread,
Aug 4, 2010, 1:40:29 PM8/4/10
to ActiveFedora / Ruby + Fedora Commons
Just tried it out. works well!

I can also delete relationships for objects that have already been
removed from Fedora by just specifying the pid directly:

parent_object.remove_relationship(:has_memenber, "pid:1234")

thanks again Rick,

...adam

On Aug 4, 1:35 pm, adam wead <amsterda...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages