Sha256: 8f35124f8077c996c8c380fc563ec17c2c313d1593a173f522a9f830ef268147
Contents?: true
Size: 1.19 KB
Versions: 33
Compression:
Stored size: 1.19 KB
Contents
module ActiveFedora module Associations class BelongsToAssociation < AssociationProxy #:nodoc: def replace(record) if record.nil? ### TODO a more efficient way of doing this would be to write a clear_relationship method old_record = find_target @owner.remove_relationship(@reflection.options[:property], old_record) unless old_record.nil? else raise_on_type_mismatch(record) ### TODO a more efficient way of doing this would be to write a clear_relationship method old_record = find_target @owner.remove_relationship(@reflection.options[:property], old_record) unless old_record.nil? @target = (AssociationProxy === record ? record.target : record) @owner.add_relationship(@reflection.options[:property], record) unless record.new_record? @updated = true end loaded record end private def find_target @owner.load_outbound_relationship(@reflection.name.to_s, @reflection.options[:property]).first end def foreign_key_present !@owner.send(@reflection.primary_key_name).nil? end end end end
Version data entries
33 entries across 33 versions & 1 rubygems