aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-01-11 00:24:19 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-01-11 00:24:19 +0000
commit79365a0184c58def99aff4c4b213048a25179f6a (patch)
tree2a33951d6e17d9a2869da4aa6eb728a71092ff5a /activerecord
parentbcb81167960293596d44587ea237ace4d505b960 (diff)
downloadrails-79365a0184c58def99aff4c4b213048a25179f6a.tar.gz
rails-79365a0184c58def99aff4c4b213048a25179f6a.tar.bz2
rails-79365a0184c58def99aff4c4b213048a25179f6a.zip
Fixed that foreign keys named the same as the association would cause stack overflow #437 [Eric Anderson]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@382 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/associations.rb4
-rwxr-xr-xactiverecord/test/associations_test.rb8
-rw-r--r--activerecord/test/fixtures/db_definitions/db2.sql5
-rwxr-xr-xactiverecord/test/fixtures/db_definitions/mysql.sql5
-rw-r--r--activerecord/test/fixtures/db_definitions/postgresql.sql5
-rw-r--r--activerecord/test/fixtures/db_definitions/sqlite.sql5
-rw-r--r--activerecord/test/fixtures/db_definitions/sqlserver.sql6
8 files changed, 36 insertions, 4 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG
index 0b2bf37496..7e29352de5 100644
--- a/activerecord/CHANGELOG
+++ b/activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Fixed that foreign keys named the same as the association would cause stack overflow #437 [Eric Anderson]
+
* Fixed default scope of acts_as_list from "1" to "1 = 1", so it'll work in PostgreSQL (among other places) #427 [Alexey]
* Added Base#reload that reloads the attributes of an object from the database #422 [Andreas Schwarz]
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index 742491ae48..e7e5a7d71d 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -336,8 +336,8 @@ module ActiveRecord
end_eval
else
association_finder = options[:conditions] ?
- "#{association_class_name}.find_on_conditions(#{association_class_primary_key_name}, \"#{options[:conditions]}\")" :
- "#{association_class_name}.find(#{association_class_primary_key_name})"
+ "#{association_class_name}.find_on_conditions(read_attribute(\"#{association_class_primary_key_name}\"), \"#{options[:conditions]}\")" :
+ "#{association_class_name}.find(read_attribute(\"#{association_class_primary_key_name}\"))"
end
has_association_method(association_name)
diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb
index 844f075f34..26640d0048 100755
--- a/activerecord/test/associations_test.rb
+++ b/activerecord/test/associations_test.rb
@@ -5,6 +5,7 @@ require 'fixtures/project'
require 'fixtures/company'
require 'fixtures/topic'
require 'fixtures/reply'
+require 'fixtures/computer'
# Can't declare new classes in test case methods, so tests before that
bad_collection_keys = false
@@ -18,7 +19,7 @@ raise "ActiveRecord should have barked on bad collection keys" unless bad_collec
class AssociationsTest < Test::Unit::TestCase
def setup
- create_fixtures "accounts", "companies", "developers", "projects", "developers_projects"
+ create_fixtures "accounts", "companies", "developers", "projects", "developers_projects", "computers"
@signals37 = Firm.find(1)
end
@@ -418,6 +419,11 @@ class BelongsToAssociationsTest < Test::Unit::TestCase
assert_equal 0, Topic.find(debate.id).send(:read_attribute, "replies_count"), "First reply deleted"
end
+ def test_field_name_same_as_foreign_key
+ computer = Computer.find 1
+ assert_not_nil computer.developer, ":foreign key == attribute didn't lock up"
+ end
+
def xtest_counter_cache
apple = Firm.create("name" => "Apple")
final_cut = apple.clients.create("name" => "Final Cut")
diff --git a/activerecord/test/fixtures/db_definitions/db2.sql b/activerecord/test/fixtures/db_definitions/db2.sql
index 7b98f2fa5a..033efcb088 100644
--- a/activerecord/test/fixtures/db_definitions/db2.sql
+++ b/activerecord/test/fixtures/db_definitions/db2.sql
@@ -122,3 +122,8 @@ CREATE TABLE binaries (
data blob(50000),
PRIMARY KEY (id)
);
+
+CREATE TABLE computers (
+ id int generated by default as identity (start with +10000),
+ developer int NOT NULL
+);
diff --git a/activerecord/test/fixtures/db_definitions/mysql.sql b/activerecord/test/fixtures/db_definitions/mysql.sql
index 3758f19bfa..0137cd91d5 100755
--- a/activerecord/test/fixtures/db_definitions/mysql.sql
+++ b/activerecord/test/fixtures/db_definitions/mysql.sql
@@ -121,4 +121,9 @@ CREATE TABLE `binaries` (
`id` int(11) NOT NULL auto_increment,
`data` mediumblob,
PRIMARY KEY (`id`)
+);
+
+CREATE TABLE `computers` (
+ `id` INTEGER NOT NULL PRIMARY KEY,
+ `developer` INTEGER NOT NULL
); \ No newline at end of file
diff --git a/activerecord/test/fixtures/db_definitions/postgresql.sql b/activerecord/test/fixtures/db_definitions/postgresql.sql
index 8f6587f961..7664c5e6e0 100644
--- a/activerecord/test/fixtures/db_definitions/postgresql.sql
+++ b/activerecord/test/fixtures/db_definitions/postgresql.sql
@@ -139,4 +139,9 @@ CREATE TABLE binaries (
id serial ,
data bytea,
PRIMARY KEY (id)
+);
+
+CREATE TABLE computers (
+ id serial,
+ developer integer NOT NULL
); \ No newline at end of file
diff --git a/activerecord/test/fixtures/db_definitions/sqlite.sql b/activerecord/test/fixtures/db_definitions/sqlite.sql
index 65b24a9333..1b9a5ea932 100644
--- a/activerecord/test/fixtures/db_definitions/sqlite.sql
+++ b/activerecord/test/fixtures/db_definitions/sqlite.sql
@@ -108,4 +108,9 @@ CREATE TABLE 'people' (
CREATE TABLE 'binaries' (
'id' INTEGER NOT NULL PRIMARY KEY,
'data' BLOB DEFAULT NULL
+);
+
+CREATE TABLE 'computers' (
+ 'id' INTEGER NOT NULL PRIMARY KEY,
+ 'developer' INTEGER NOT NULL
); \ No newline at end of file
diff --git a/activerecord/test/fixtures/db_definitions/sqlserver.sql b/activerecord/test/fixtures/db_definitions/sqlserver.sql
index 023ab63406..95106a7b18 100644
--- a/activerecord/test/fixtures/db_definitions/sqlserver.sql
+++ b/activerecord/test/fixtures/db_definitions/sqlserver.sql
@@ -122,4 +122,8 @@ CREATE TABLE binaries (
PRIMARY KEY (id)
);
-
+CREATE TABLE computers (
+ id int NOT NULL IDENTITY(1, 1),
+ developer int NOT NULL,
+ PRIMARY KEY (id)
+);