aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-01-16 21:28:47 +0000
committerAaron Patterson <aaron.patterson@gmail.com>2011-01-16 13:43:54 -0800
commitd1521719c5ac61a0c0e59827fe8cb197f5fe56f5 (patch)
tree6a64320e36d329a5addeeb0f5dda86466eae072e /activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
parentc4458b36024a20abacc39c069444bb0ac202778a (diff)
downloadrails-d1521719c5ac61a0c0e59827fe8cb197f5fe56f5.tar.gz
rails-d1521719c5ac61a0c0e59827fe8cb197f5fe56f5.tar.bz2
rails-d1521719c5ac61a0c0e59827fe8cb197f5fe56f5.zip
Removed support for accessing attributes on a has_and_belongs_to_many join table. This has been documented as deprecated behaviour since April 2006. Please use has_many :through instead. A deprecation warning will be added to the 3-0-stable branch for the 3.0.4 release.
Diffstat (limited to 'activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb')
-rw-r--r--activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb68
1 files changed, 6 insertions, 62 deletions
diff --git a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
index bc7894173d..b28554dce1 100644
--- a/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
+++ b/activerecord/lib/active_record/associations/has_and_belongs_to_many_association.rb
@@ -10,18 +10,6 @@ module ActiveRecord
super
end
- def columns
- @reflection.columns(@join_table_name, "#{@join_table_name} Columns")
- end
-
- def reset_column_information
- @reflection.reset_column_information
- end
-
- def has_primary_key?
- @has_primary_key ||= @owner.connection.supports_primary_key? && @owner.connection.primary_key(@join_table_name)
- end
-
protected
def count_records
@@ -36,26 +24,11 @@ module ActiveRecord
if @reflection.options[:insert_sql]
@owner.connection.insert(interpolate_sql(@reflection.options[:insert_sql], record))
else
- relation = join_table
- timestamps = record_timestamp_columns(record)
- timezone = record.send(:current_time_from_proper_timezone) if timestamps.any?
-
- attributes = columns.map do |column|
- name = column.name
- value = case name.to_s
- when @reflection.foreign_key.to_s
- @owner.id
- when @reflection.association_foreign_key.to_s
- record.id
- when *timestamps
- timezone
- else
- @owner.send(:quote_value, record[name], column) if record.has_attribute?(name)
- end
- [relation[name], value] unless value.nil?
- end
+ stmt = join_table.compile_insert(
+ join_table[@reflection.foreign_key] => @owner.id,
+ join_table[@reflection.association_foreign_key] => record.id
+ )
- stmt = relation.compile_insert Hash[attributes]
@owner.connection.insert stmt.to_sql
end
@@ -89,46 +62,17 @@ module ActiveRecord
end
def association_scope
- scope = super.joins(construct_joins)
- scope = scope.readonly if ambiguous_select?(@reflection.options[:select])
- scope
+ super.joins(construct_joins)
end
def select_value
- super || [@reflection.klass.arel_table[Arel.star], join_table[Arel.star]]
- end
-
- # Join tables with additional columns on top of the two foreign keys must be considered
- # ambiguous unless a select clause has been explicitly defined. Otherwise you can get
- # broken records back, if, for example, the join column also has an id column. This will
- # then overwrite the id column of the records coming back.
- def ambiguous_select?(select)
- extra_join_columns? && select.nil?
- end
-
- def extra_join_columns?
- columns.size > 2
+ super || @reflection.klass.arel_table[Arel.star]
end
private
- def record_timestamp_columns(record)
- if record.record_timestamps
- record.send(:all_timestamp_attributes).map { |x| x.to_s }
- else
- []
- end
- end
-
def invertible_for?(record)
false
end
-
- def find_by_sql(*args)
- options = args.extract_options!
- ambiguous = ambiguous_select?(@reflection.options[:select] || options[:select])
-
- scoped.readonly(ambiguous).find(*(args << options))
- end
end
end
end