Sha256: 60a8ffe6752912461f4d19cd4f34e6b0940e93e49e0d4d00321997caf6053783

Contents?: true

Size: 809 Bytes

Versions: 138

Compression:

Stored size: 809 Bytes

Contents

module ActiveRecord::Associations::Builder
  class SingularAssociation < Association #:nodoc:
    self.valid_options += [:remote, :dependent, :counter_cache, :primary_key, :inverse_of]

    def constructable?
      true
    end

    def define_accessors
      super
      define_constructors if constructable?
    end

    private

      def define_constructors
        name = self.name

        mixin.redefine_method("build_#{name}") do |*params, &block|
          association(name).build(*params, &block)
        end

        mixin.redefine_method("create_#{name}") do |*params, &block|
          association(name).create(*params, &block)
        end

        mixin.redefine_method("create_#{name}!") do |*params, &block|
          association(name).create!(*params, &block)
        end
      end
  end
end

Version data entries

138 entries across 107 versions & 14 rubygems

Version Path
mdg-1.0.1 vendor/bundle/ruby/2.3.0/gems/activerecord-3.2.22.5/lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.22.5 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.22.4 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.22.3 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.22.2 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.22.1 lib/active_record/associations/builder/singular_association.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.12/lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.22 lib/active_record/associations/builder/singular_association.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.12/lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.21 lib/active_record/associations/builder/singular_association.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.18/lib/active_record/associations/builder/singular_association.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.8/gems/activerecord-3.2.18/lib/active_record/associations/builder/singular_association.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/2.1.0/gems/activerecord-3.2.18/lib/active_record/associations/builder/singular_association.rb
apl-library-0.0.90 vendor/bundle/ruby/2.1.0/gems/apl-library-0.0.90/vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/associations/builder/singular_association.rb
apl-library-0.0.90 vendor/bundle/ruby/1.8/gems/activerecord-3.2.18/lib/active_record/associations/builder/singular_association.rb
apl-library-0.0.90 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.18/lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.20 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.19 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.18 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.17 lib/active_record/associations/builder/singular_association.rb