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
activerecord-3.2.16 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.15 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.15.rc3 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.15.rc2 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.15.rc1 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.14 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.14.rc2 lib/active_record/associations/builder/singular_association.rb
activerecord-3.2.14.rc1 lib/active_record/associations/builder/singular_association.rb
swipe-rails-0.0.5 vendor/bundle/gems/activerecord-3.2.13/lib/active_record/associations/builder/singular_association.rb
active_mailer-0.0.9 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
active_mailer-0.0.8 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
active_mailer-0.0.7 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
active_mailer-0.0.6 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
challah-1.0.0.beta3 vendor/bundle/gems/activerecord-3.2.13/lib/active_record/associations/builder/singular_association.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/builder/singular_association.rb
challah-1.0.0.beta2 vendor/bundle/gems/activerecord-3.2.13/lib/active_record/associations/builder/singular_association.rb
challah-1.0.0.beta vendor/bundle/gems/activerecord-3.2.11/lib/active_record/associations/builder/singular_association.rb
challah-1.0.0.beta vendor/bundle/gems/activerecord-3.2.13/lib/active_record/associations/builder/singular_association.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/builder/singular_association.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/activerecord-3.2.13/lib/active_record/associations/builder/singular_association.rb