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

Version Path
active-fedora-3.1.6 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.2.0.pre1 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.5 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.4 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.3 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.2 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.1 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.0 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.0.rc4 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.0.rc3 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.0.rc2 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.0.rc1 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.0.pre14 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.0.pre13 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.0.pre12 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.0.pre11 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.0.pre10 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.1.0.pre9 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.0.7 lib/active_fedora/associations/belongs_to_association.rb
active-fedora-3.0.6 lib/active_fedora/associations/belongs_to_association.rb