aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2009-09-02 13:55:02 -0700
committerJeremy Kemper <jeremy@bitsweat.net>2009-09-02 13:55:47 -0700
commit3b6a9a020e7e6f71ab6f9ffcf1ef59c57437ca69 (patch)
tree90df5808a8788bf48c1079989d0171495a75e0d6 /activerecord/lib/active_record/associations.rb
parent723a47bfb3708f968821bc969a9a3fc873a3ed58 (diff)
downloadrails-3b6a9a020e7e6f71ab6f9ffcf1ef59c57437ca69.tar.gz
rails-3b6a9a020e7e6f71ab6f9ffcf1ef59c57437ca69.tar.bz2
rails-3b6a9a020e7e6f71ab6f9ffcf1ef59c57437ca69.zip
Revert "Assert primary key does not exist in habtm when the association is defined, instead of doing that everytime a record is inserted."
Test failures on PostgreSQL. [#3128 state:open] This reverts commit da636809daca9c338200811d3590e446f57c8e81.
Diffstat (limited to 'activerecord/lib/active_record/associations.rb')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb22
1 files changed, 11 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 1c20af9adb..02dfb7b400 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -60,12 +60,6 @@ module ActiveRecord
end
end
- class HasAndBelongsToManyAssociationWithPrimaryKeyError < ActiveRecordError #:nodoc:
- def initialize(reflection)
- super("Primary key is not allowed in a has_and_belongs_to_many join table (#{reflection.options[:join_table]}).")
- end
- end
-
class HasAndBelongsToManyAssociationForeignKeyNeeded < ActiveRecordError #:nodoc:
def initialize(reflection)
super("Cannot create self referential has_and_belongs_to_many association on '#{reflection.class_name rescue nil}##{reflection.name rescue nil}'. :association_foreign_key cannot be the same as the :foreign_key.")
@@ -1658,19 +1652,16 @@ module ActiveRecord
def create_has_and_belongs_to_many_reflection(association_id, options, &extension)
options.assert_valid_keys(valid_keys_for_has_and_belongs_to_many_association)
+
options[:extend] = create_extension_modules(association_id, extension, options[:extend])
reflection = create_reflection(:has_and_belongs_to_many, association_id, options, self)
- reflection.options[:join_table] ||= join_table_name(undecorated_table_name(self.to_s), undecorated_table_name(reflection.class_name))
if reflection.association_foreign_key == reflection.primary_key_name
raise HasAndBelongsToManyAssociationForeignKeyNeeded.new(reflection)
end
- if connection.supports_primary_key? &&
- (connection.primary_key(reflection.options[:join_table]) rescue false)
- raise HasAndBelongsToManyAssociationWithPrimaryKeyError.new(reflection)
- end
+ reflection.options[:join_table] ||= join_table_name(undecorated_table_name(self.to_s), undecorated_table_name(reflection.class_name))
reflection
end
@@ -1679,6 +1670,15 @@ module ActiveRecord
[ associations ].flatten.collect { |association| reflect_on_association(association.to_s.intern) }
end
+ def guard_against_unlimitable_reflections(reflections, options)
+ if (options[:offset] || options[:limit]) && !using_limitable_reflections?(reflections)
+ raise(
+ ConfigurationError,
+ "You can not use offset and limit together with has_many or has_and_belongs_to_many associations"
+ )
+ end
+ end
+
def select_all_rows(options, join_dependency)
connection.select_all(
construct_finder_sql_with_included_associations(options, join_dependency),