Class: ActiveRecord::Associations::HasAndBelongsToManyAssociation

Inherits:
AssociationCollection show all
Defined in:
lib/active_record/associations/has_and_belongs_to_many_association.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from AssociationCollection

#<<, #any?, #build, #clear, #count, #delete, #delete_all, #destroy, #destroy_all, #empty?, #find, #first, #include?, #last, #length, #many?, #proxy_respond_to?, #replace, #reset, #scoped, #select, #size, #sum, #to_ary, #transaction, #uniq

Methods inherited from AssociationProxy

#===, #aliased_table_name, #conditions, #inspect, #loaded, #loaded?, #proxy_owner, #proxy_reflection, #proxy_respond_to?, #proxy_target, #reload, #reset, #respond_to?, #send, #target, #target=

Constructor Details

#initialize(owner, reflection) ⇒ HasAndBelongsToManyAssociation

Returns a new instance of HasAndBelongsToManyAssociation.



7
8
9
10
11
12
# File 'lib/active_record/associations/has_and_belongs_to_many_association.rb', line 7

def initialize(owner, reflection)
  super
  if columns.size > 2
    ActiveSupport::Deprecation.warn "Having additional attributes on the join table of a has_and_belongs_to_many association is deprecated and will be removed in Rails 3.1. Please use a has_many :through association instead."
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ActiveRecord::Associations::AssociationCollection

Instance Method Details

#columnsObject



22
23
24
# File 'lib/active_record/associations/has_and_belongs_to_many_association.rb', line 22

def columns
  @reflection.columns(@reflection.options[:join_table], "#{@reflection.options[:join_table]} Columns")
end

#create(attributes = {}) ⇒ Object



14
15
16
# File 'lib/active_record/associations/has_and_belongs_to_many_association.rb', line 14

def create(attributes = {})
  create_record(attributes) { |record| insert_record(record) }
end

#create!(attributes = {}) ⇒ Object



18
19
20
# File 'lib/active_record/associations/has_and_belongs_to_many_association.rb', line 18

def create!(attributes = {})
  create_record(attributes) { |record| insert_record(record, true) }
end

#has_primary_key?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/active_record/associations/has_and_belongs_to_many_association.rb', line 30

def has_primary_key?
  @has_primary_key ||= @owner.connection.supports_primary_key? && @owner.connection.primary_key(@reflection.options[:join_table])
end

#reset_column_informationObject



26
27
28
# File 'lib/active_record/associations/has_and_belongs_to_many_association.rb', line 26

def reset_column_information
  @reflection.reset_column_information
end