Permalink
Browse files

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
  • Loading branch information...
1 parent bcb8116 commit 79365a0184c58def99aff4c4b213048a25179f6a @dhh dhh committed Jan 11, 2005
View
@@ -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]
@@ -336,8 +336,8 @@ def belongs_to(association_id, options = {})
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)
@@ -5,6 +5,7 @@
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 @@ class Car < ActiveRecord::Base; has_many :wheels, :name => "wheels"; end
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 @@ def test_belongs_to_counter
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")
@@ -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
+);
@@ -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
);
@@ -139,4 +139,9 @@ CREATE TABLE binaries (
id serial ,
data bytea,
PRIMARY KEY (id)
+);
+
+CREATE TABLE computers (
+ id serial,
+ developer integer NOT NULL
);
@@ -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
);
@@ -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)
+);

0 comments on commit 79365a0

Please sign in to comment.