Skip to content
This repository
Newer
Older
100644 59 lines (49 sloc) 1.681 kb
db045dbb »
2004-11-24 Initial
1 module ActiveRecord
fde95048 »
2010-06-16 Adds title to activerecord/lib/active_record/associations/*
2 # = Active Record Has And Belongs To Many Association
db045dbb »
2004-11-24 Initial
3 module Associations
1644663b »
2011-02-17 Split AssociationProxy into an Association class (and subclasses) whi…
4 class HasAndBelongsToManyAssociation < CollectionAssociation #:nodoc:
90171ad8 »
2011-01-05 avoid creating so many Arel::Table objects
5 attr_reader :join_table
6
7 def initialize(owner, reflection)
c5e912a8 »
2011-01-26 @join_table_name is no longer used
8 @join_table = Arel::Table.new(reflection.options[:join_table])
90171ad8 »
2011-01-05 avoid creating so many Arel::Table objects
9 super
10 end
3103296a »
2011-01-02 Let AssociationCollection#find use #scoped to do its finding. Note th…
11
dfaad4f5 »
2011-05-31 Only save the record once when calling create! on a collection associ…
12 def insert_record(record, validate = true, raise = false)
13 if record.new_record?
14 if raise
15 record.save!(:validate => validate)
16 else
17 return unless record.save(:validate => validate)
18 end
19 end
c1f833df »
2009-08-18 habtm delete method integrated with ARel.
20
32eef69d »
2011-02-20 Delegate Association#options to the reflection, and replace 'reflecti…
21 if options[:insert_sql]
22 owner.connection.insert(interpolate(options[:insert_sql], record))
1644663b »
2011-02-17 Split AssociationProxy into an Association class (and subclasses) whi…
23 else
24 stmt = join_table.compile_insert(
1d85a73c »
2011-02-20 Associations - where possible, call attributes methods rather than di…
25 join_table[reflection.foreign_key] => owner.id,
26 join_table[reflection.association_foreign_key] => record.id
1644663b »
2011-02-17 Split AssociationProxy into an Association class (and subclasses) whi…
27 )
b29c01ea »
2005-01-24 Added that has_and_belongs_to_many associations with additional attri…
28
1d85a73c »
2011-02-20 Associations - where possible, call attributes methods rather than di…
29 owner.connection.insert stmt.to_sql
db045dbb »
2004-11-24 Initial
30 end
800b899f »
2007-06-11 Remove deprecated push_with_attributes.
31
1644663b »
2011-02-17 Split AssociationProxy into an Association class (and subclasses) whi…
32 record
33 end
34
15601c52 »
2011-01-24 Let's be less blasé about method visibility on association proxies
35 private
36
37 def count_records
38 load_target.size
39 end
40
e62b5764 »
2011-02-06 Refactor the implementations of AssociatioCollection#delete and #dest…
41 def delete_records(records, method)
32eef69d »
2011-02-20 Delegate Association#options to the reflection, and replace 'reflecti…
42 if sql = options[:delete_sql]
1d85a73c »
2011-02-20 Associations - where possible, call attributes methods rather than di…
43 records.each { |record| owner.connection.delete(interpolate(sql, record)) }
db045dbb »
2004-11-24 Initial
44 else
8bdc1919 »
2011-01-05 we have a method for this, so let's use it
45 relation = join_table
1d85a73c »
2011-02-20 Associations - where possible, call attributes methods rather than di…
46 stmt = relation.where(relation[reflection.foreign_key].eq(owner.id).
47 and(relation[reflection.association_foreign_key].in(records.map { |x| x.id }.compact))
9a3e29e1 »
2010-12-02 remove calls to deprecated methods
48 ).compile_delete
1d85a73c »
2011-02-20 Associations - where possible, call attributes methods rather than di…
49 owner.connection.delete stmt.to_sql
db045dbb »
2004-11-24 Initial
50 end
51 end
a3bd62e1 »
2010-11-25 Remove explicit return.
52
9f5c18ce »
2010-12-26 Refactor we_can_set_the_inverse_on_this? to use a less bizarre name a…
53 def invertible_for?(record)
54 false
55 end
823554ea »
2005-01-15 Added support for associating unsaved objects #402 [Tim Bates]
56 end
db045dbb »
2004-11-24 Initial
57 end
68d10565 »
2004-12-14 Fixed that has_and_belongs_to_many would generate bad sql when naming…
58 end
Something went wrong with that request. Please try again.