Sha256: d6187f100081011122262ef7be303418318f85e61e47c59c26de7c70e261f7ad

Contents?: true

Size: 759 Bytes

Versions: 18

Compression:

Stored size: 759 Bytes

Contents

module ActiveRecord::Associations::Builder
  class SingularAssociation < Association #:nodoc:
    def valid_options
      super + [:remote, :dependent, :primary_key, :inverse_of]
    end

    def constructable?
      true
    end

    def define_accessors
      super
      define_constructors if constructable?
    end

    def define_constructors
      mixin.class_eval <<-CODE, __FILE__, __LINE__ + 1
        def build_#{name}(*args, &block)
          association(:#{name}).build(*args, &block)
        end

        def create_#{name}(*args, &block)
          association(:#{name}).create(*args, &block)
        end

        def create_#{name}!(*args, &block)
          association(:#{name}).create!(*args, &block)
        end
      CODE
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
activerecord-4.0.13 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.13.rc1 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.11.1 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.12 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.11 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.10 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.10.rc2 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.10.rc1 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.9 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.8 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.7 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.6 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.6.rc3 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.6.rc2 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.6.rc1 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.5 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.4 lib/active_record/associations/builder/singular_association.rb
activerecord-4.0.4.rc1 lib/active_record/associations/builder/singular_association.rb