Sha256: 26c78baa74ea1a24d1e1a6233cad23fd015160e0287a1115ac6de812e292d5ee

Contents?: true

Size: 1.56 KB

Versions: 32

Compression:

Stored size: 1.56 KB

Contents

module ActiveFedora
  module Associations
    class HasManyAssociation < AssociationCollection #:nodoc:
      def initialize(owner, reflection)
        super
      end

      # Returns the number of records in this collection.
      #
      # That does not depend on whether the collection has already been loaded
      # or not. The +size+ method is the one that takes the loaded flag into
      # account and delegates to +count_records+ if needed.
      #
      # If the collection is empty the target is set to an empty array and
      # the loaded flag is set to true as well.
      def count_records
        count = if loaded? 
          @target.size
        else
          @reflection.klass.count(:conditions => @counter_query)
          # load_target
          # @target.size
        end

        # If there's nothing in the database and @target has no new records
        # we are certain the current target is an empty array. This is a
        # documented side-effect of the method that may avoid an extra SELECT.
        @target ||= [] and loaded if count == 0

        return count
      end

      def insert_record(record, force = false, validate = true)
        set_belongs_to_association_for(record)
        #force ? record.save! : record.save(:validate => validate)
        record.save
      end

      protected

        # Deletes the records according to the <tt>:dependent</tt> option.
        def delete_records(records)
          records.each do |r| 
            r.remove_relationship(@reflection.options[:property], @owner)
          end
        end

        
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
active-fedora-6.0.0 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.rc7 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.rc6 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.rc5 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.rc4 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.rc3 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.rc2 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.rc1 lib/active_fedora/associations/has_many_association.rb
active-fedora-5.6.2 lib/active_fedora/associations/has_many_association.rb
active-fedora-5.6.1 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.pre10 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.pre9 lib/active_fedora/associations/has_many_association.rb
active-fedora-5.6.0 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.pre8 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.pre7 lib/active_fedora/associations/has_many_association.rb
active-fedora-5.5.2 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.pre6 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.pre5 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.pre4 lib/active_fedora/associations/has_many_association.rb
active-fedora-6.0.0.pre3 lib/active_fedora/associations/has_many_association.rb