Sha256: 436a57bd9dcb3489fbc5193f634761435dd70c95801bca8e7ee71160b8bfb643
Contents?: true
Size: 1.79 KB
Versions: 34
Compression:
Stored size: 1.79 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 def construct_query internal_uri = @owner.internal_uri escaped_uri = internal_uri.gsub(/(:)/, '\\:') @counter_query = @finder_query = "#{@reflection.options[:property]}_s:#{escaped_uri}" end end end end
Version data entries
34 entries across 34 versions & 1 rubygems