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, #proxy_respond_to?, #replace, #reset, #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.



4
5
6
7
# File 'lib/active_record/associations/has_and_belongs_to_many_association.rb', line 4

def initialize(owner, reflection)
  super
  @primary_key_list = {}
end

Dynamic Method Handling

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

Instance Method Details

#columnsObject



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

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

#create(attributes = {}) ⇒ Object



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

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

#create!(attributes = {}) ⇒ Object



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

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

#has_primary_key?Boolean

Returns:

  • (Boolean)


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

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

#reset_column_informationObject



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

def reset_column_information
  @reflection.reset_column_information
end