Class: ActiveFedora::Associations::BelongsToAssociation
Overview
Instance Attribute Summary
Attributes inherited from Association
#owner, #reflection, #target
Instance Method Summary
collapse
#build, #create, #create!, #reader, #writer
Methods inherited from Association
#association_scope, #initialize, #load_target, #loaded!, #loaded?, #reload, #scope, #set_inverse_instance, #stale_target?, #target_scope
Instance Method Details
#id_reader ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 11
def id_reader
ids = @owner.ids_for_outbound(@reflection.options[:property])
return if ids.empty?
results = SolrService.query(ActiveFedora::SolrService.construct_query_for_pids(ids))
results.each do |result|
return result['id'] if SolrService.class_from_solr_document(result) == klass
end
return nil
end
|
#id_writer(id) ⇒ Object
5
6
7
8
9
|
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 5
def id_writer(id)
remove_matching_property_relationship
return if id.blank? or id == ActiveFedora::UnsavedDigitalObject::PLACEHOLDER
@owner.add_relationship(@reflection.options[:property], ActiveFedora::Base.internal_uri(id))
end
|
#replace(record) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 27
def replace(record)
if record.nil?
id_writer(nil)
else
raise_on_type_mismatch(record)
id_writer(record.id)
@updated = true
end
self.target = record
loaded!
record
end
|
#reset ⇒ Object
43
44
45
46
|
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 43
def reset
super
@updated = false
end
|
#updated? ⇒ Boolean
48
49
50
|
# File 'lib/active_fedora/associations/belongs_to_association.rb', line 48
def updated?
@updated
end
|