Class: ActiveFedora::Associations::BasicContainsAssociation

Inherits:
ContainsAssociation show all
Defined in:
lib/active_fedora/associations/basic_contains_association.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from CollectionAssociation

#proxy

Attributes inherited from Association

#inversed, #owner, #reflection, #target

Instance Method Summary collapse

Methods inherited from ContainsAssociation

#include?, #reader

Methods inherited from CollectionAssociation

#any?, #build, #concat, #concat_records, #count, #create, #create!, #delete, #delete_all, #destroy, #destroy_all, #empty?, #find, #first, #ids_reader, #ids_writer, #include?, #last, #load_from_solr, #load_target, #null_scope?, #reader, #replace, #scope, #select, #size, #target=, #to_ary, #writer

Methods inherited from Association

#association_scope, #initialize, #initialize_attributes, #load_target, #loaded!, #loaded?, #reload, #reset_scope, #scope, #set_inverse_instance, #stale_target?, #target_scope

Constructor Details

This class inherits a constructor from ActiveFedora::Associations::Association

Instance Method Details

#add_to_target(record, skip_callbacks = false) ⇒ Object



16
17
18
19
# File 'lib/active_fedora/associations/basic_contains_association.rb', line 16

def add_to_target(record, skip_callbacks = false)
  record.base_path_for_resource = owner.uri.to_s
  super
end

#find_targetObject



4
5
6
7
8
9
# File 'lib/active_fedora/associations/basic_contains_association.rb', line 4

def find_target
  uris = owner.resource.query({ predicate: options[:predicate] })
              .map { |r| r.object.to_s }

  uris.map { |object_uri| klass.find(klass.uri_to_id(object_uri)) }
end

#insert_record(record, force = true, validate = true) ⇒ Object



11
12
13
14
# File 'lib/active_fedora/associations/basic_contains_association.rb', line 11

def insert_record(record, force = true, validate = true)
  record.base_path_for_resource = owner.uri.to_s
  super
end

#resetObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/active_fedora/associations/basic_contains_association.rb', line 21

def reset
  # Update the membership triples (and no other triples) on the the owner's resource
  if owner.persisted?
    pattern = ::RDF::Query::Pattern.new(predicate: options[:predicate])
    new_resource = ActiveFedora::Base.uncached do
      owner.dup.reload.resource
    end
    owner.resource.delete_insert([pattern], new_resource.query(pattern))
  end
  super
end