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:
parent
4f00d181d5
commit
a2f26b971b
@ -1,5 +1,7 @@
|
|||||||
*SVN*
|
*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
|
* 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]
|
* Allow any Enumerable, not just Array, to work as bind variables #1344 [Jeremy Kemper]
|
||||||
|
@ -104,7 +104,9 @@ def count_records
|
|||||||
end
|
end
|
||||||
|
|
||||||
def insert_record(record)
|
def insert_record(record)
|
||||||
return false unless record.save
|
if record.new_record?
|
||||||
|
return false unless record.save
|
||||||
|
end
|
||||||
|
|
||||||
if @options[:insert_sql]
|
if @options[:insert_sql]
|
||||||
@owner.connection.execute(interpolate_sql(@options[:insert_sql], record))
|
@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
|
assert_equal 2, action_controller.developers(true).size
|
||||||
end
|
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
|
def test_adding_multiple
|
||||||
aredridel = Developer.new("name" => "Aredridel")
|
aredridel = Developer.new("name" => "Aredridel")
|
||||||
aredridel.save
|
aredridel.save
|
||||||
|
@ -36,6 +36,8 @@ CREATE TABLE developers (
|
|||||||
id int generated by default as identity (start with +10000),
|
id int generated by default as identity (start with +10000),
|
||||||
name varchar(100) default NULL,
|
name varchar(100) default NULL,
|
||||||
salary int default 70000,
|
salary int default 70000,
|
||||||
|
created_at timestamp default NULL,
|
||||||
|
updated_at timestamp default NULL,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -37,6 +37,8 @@ CREATE TABLE `developers` (
|
|||||||
`id` int(11) NOT NULL auto_increment,
|
`id` int(11) NOT NULL auto_increment,
|
||||||
`name` varchar(100) default NULL,
|
`name` varchar(100) default NULL,
|
||||||
`salary` int(11) default 70000,
|
`salary` int(11) default 70000,
|
||||||
|
`created_at` datetime default NULL,
|
||||||
|
`updated_at` datetime default NULL,
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) TYPE=InnoDB;
|
) TYPE=InnoDB;
|
||||||
|
|
||||||
|
@ -55,6 +55,8 @@ create table developers (
|
|||||||
id integer not null,
|
id integer not null,
|
||||||
name varchar(100) default null,
|
name varchar(100) default null,
|
||||||
salary integer default 70000,
|
salary integer default 70000,
|
||||||
|
created_at timestamp default null,
|
||||||
|
updated_at timestamp default null,
|
||||||
primary key (id)
|
primary key (id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ CREATE TABLE developers (
|
|||||||
id serial,
|
id serial,
|
||||||
name character varying(100),
|
name character varying(100),
|
||||||
salary integer DEFAULT 70000,
|
salary integer DEFAULT 70000,
|
||||||
|
created_at timestamp,
|
||||||
|
updated_at timestamp,
|
||||||
PRIMARY KEY (id)
|
PRIMARY KEY (id)
|
||||||
);
|
);
|
||||||
SELECT setval('developers_id_seq', 100);
|
SELECT setval('developers_id_seq', 100);
|
||||||
|
@ -33,7 +33,9 @@ CREATE TABLE 'topics' (
|
|||||||
CREATE TABLE 'developers' (
|
CREATE TABLE 'developers' (
|
||||||
'id' INTEGER PRIMARY KEY NOT NULL,
|
'id' INTEGER PRIMARY KEY NOT NULL,
|
||||||
'name' TEXT DEFAULT 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' (
|
CREATE TABLE 'projects' (
|
||||||
|
@ -32,7 +32,9 @@ CREATE TABLE topics (
|
|||||||
CREATE TABLE developers (
|
CREATE TABLE developers (
|
||||||
id int NOT NULL IDENTITY(1, 1) PRIMARY KEY,
|
id int NOT NULL IDENTITY(1, 1) PRIMARY KEY,
|
||||||
name varchar(100) default NULL,
|
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 (
|
CREATE TABLE projects (
|
||||||
|
Loading…
Reference in New Issue
Block a user