Sha256: acf9289625b641b55db3afd40e08336da213e9c4be69cfd173a247d0cb65530f

Contents?: true

Size: 1.11 KB

Versions: 12

Compression:

Stored size: 1.11 KB

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Associations #:nodoc:
    # Represents an relational one-to-many association with an object in a
    # separate collection or database.
    class HasManyRelated < Proxy
      
      def initialize_with_custom_fields(parent, options, target_array = nil)
        if custom_fields?(parent, options.name)
          options = options.clone # 2 parent instances should not share the exact same option instance
          
          custom_fields = parent.send(:"ordered_#{custom_fields_association_name(options.name)}")
          
          klass = options.klass.to_klass_with_custom_fields(custom_fields)
          klass._parent = parent
          klass.association_name = options.name
          
          options.instance_eval <<-EOF
            def klass=(klass); @klass = klass; end
            def klass; @klass || class_name.constantize; end
          EOF
          
          options.klass = klass
        end
        
        initialize_without_custom_fields(parent, options, target_array)
      end
      
      alias_method_chain :initialize, :custom_fields
      
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
locomotive_cms-0.0.3.3 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/has_many_related.rb
locomotive_cms-0.0.3.1 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/has_many_related.rb
locomotive_cms-0.0.2.9 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/has_many_related.rb
locomotive_cms-0.0.2.8 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/has_many_related.rb
locomotive_cms-0.0.2.7 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/has_many_related.rb
locomotive_cms-0.0.2.6 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/has_many_related.rb
locomotive_cms-0.0.2.5 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/has_many_related.rb
locomotive_cms-0.0.2.4 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/has_many_related.rb
locomotive_cms-0.0.2.3 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/has_many_related.rb
locomotive_cms-0.0.2.2 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/has_many_related.rb
locomotive_cms-0.0.2.1 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/has_many_related.rb
locomotive_cms-0.0.2 vendor/plugins/custom_fields/lib/custom_fields/extensions/mongoid/associations/has_many_related.rb