Sha256: 53c4a6979a689b82346159c124cc29e4710002181afaf6a3e5e8ca12a0596ea2

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 KB

Contents

module Mongoid #:nodoc:
  module Relations #:nodoc:
    module Referenced #:nodoc:

      # This class defines the behaviour for all relations that are a
      # one-to-many between documents in different collections.
      class Many < Relations::Many

        def build_with_custom_fields(attributes = {}, type = nil)
          if base.respond_to?(:custom_fields_for?) && base.custom_fields_for?(relation_metadata.name)
            # all the information about how to build the custom class are stored here
            recipe = base.custom_fields_recipe_for(relation_metadata.name)
            attributes ||= {}
            attributes.merge!(custom_fields_recipe: recipe)
            # build the class with custom_fields for the first time
            type = relation_metadata.klass.klass_with_custom_fields(recipe)
          end
          build_without_custom_fields(attributes, type)
        end
        alias_method_chain :build, :custom_fields

        # new should point to the new build method
        alias :new :build_with_custom_fields
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
custom_fields-2.8.0 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
custom_fields-2.7.0 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
custom_fields-2.7.0.rc1 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
custom_fields-2.6.0 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
custom_fields-2.5.0 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
custom_fields-2.5.0.rc1 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
custom_fields-2.4.0.rc8 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
custom_fields-2.4.0.rc7 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
custom_fields-2.4.0.rc6 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
custom_fields-2.4.0.rc5 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
custom_fields-2.4.0.rc4 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
custom_fields-2.4.0.rc3 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb
custom_fields-2.4.0.rc2 lib/custom_fields/extensions/mongoid/relations/referenced/many.rb