Fixed that adding a record to a has_and_belongs_to collection would always save it -- now it only saves if its a new record #1203 [Alisdair McDiarmid]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1453 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
David Heinemeier Hansson 2005-06-18 05:28:59 +00:00
parent 4f00d181d5
commit a2f26b971b
9 changed files with 35 additions and 3 deletions

@ -1,5 +1,7 @@
*SVN*
* Fixed that adding a record to a has_and_belongs_to collection would always save it -- now it only saves if its a new record #1203 [Alisdair McDiarmid]
* Fixed saving of in-memory association structures to happen as a after_create/after_update callback instead of after_save -- that way you can add new associations in after_create/after_update callbacks without getting them saved twice
* Allow any Enumerable, not just Array, to work as bind variables #1344 [Jeremy Kemper]

@ -104,7 +104,9 @@ def count_records
end
def insert_record(record)
return false unless record.save
if record.new_record?
return false unless record.save
end
if @options[:insert_sql]
@owner.connection.execute(interpolate_sql(@options[:insert_sql], record))

@ -823,6 +823,22 @@ def test_adding_from_the_project
assert_equal 2, action_controller.developers(true).size
end
def test_adding_from_the_project_fixed_timestamp
jamis = Developer.find(2)
action_controller = Project.find(2)
action_controller.developers.reload
assert_equal 1, jamis.projects.size
assert_equal 1, action_controller.developers.size
updated_at = jamis.updated_at
action_controller.developers << jamis
assert_equal updated_at, jamis.updated_at
assert_equal 2, jamis.projects(true).size
assert_equal 2, action_controller.developers.size
assert_equal 2, action_controller.developers(true).size
end
def test_adding_multiple
aredridel = Developer.new("name" => "Aredridel")
aredridel.save

@ -36,6 +36,8 @@ CREATE TABLE developers (
id int generated by default as identity (start with +10000),
name varchar(100) default NULL,
salary int default 70000,
created_at timestamp default NULL,
updated_at timestamp default NULL,
PRIMARY KEY (id)
);

@ -37,6 +37,8 @@ CREATE TABLE `developers` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(100) default NULL,
`salary` int(11) default 70000,
`created_at` datetime default NULL,
`updated_at` datetime default NULL,
PRIMARY KEY (`id`)
) TYPE=InnoDB;

@ -55,6 +55,8 @@ create table developers (
id integer not null,
name varchar(100) default null,
salary integer default 70000,
created_at timestamp default null,
updated_at timestamp default null,
primary key (id)
);

@ -28,6 +28,8 @@ CREATE TABLE developers (
id serial,
name character varying(100),
salary integer DEFAULT 70000,
created_at timestamp,
updated_at timestamp,
PRIMARY KEY (id)
);
SELECT setval('developers_id_seq', 100);

@ -33,7 +33,9 @@ CREATE TABLE 'topics' (
CREATE TABLE 'developers' (
'id' INTEGER PRIMARY KEY NOT NULL,
'name' TEXT DEFAULT NULL,
'salary' INTEGER DEFAULT 70000
'salary' INTEGER DEFAULT 70000,
'created_at' DATETIME DEFAULT NULL,
'updated_at' DATETIME DEFAULT NULL
);
CREATE TABLE 'projects' (

@ -32,7 +32,9 @@ CREATE TABLE topics (
CREATE TABLE developers (
id int NOT NULL IDENTITY(1, 1) PRIMARY KEY,
name varchar(100) default NULL,
salary int default 70000
salary int default 70000,
created_at datetime default NULL,
updated_at datetime default NULL
);
CREATE TABLE projects (