Hi All,
I''m trying to set up a region tree, and when I unit test the class,
the fixure does not seem to load ''in order'', and as a result i
get the
following error:
test_traverse(RegionTest):
ActiveRecord::StatementInvalid: ERROR C23503 Minsert or update on
table "region" violates foreign key constraint
"fk_region_parent"
DKey (parent_id)=(4) is not present in table "region". Fri_triggers.c
L3290 Rri_ReportViolation: INSERT INTO region ("name",
"country_id", "id", "parent_id") VALUES
(''West End'', 1, 5, 4)
''test_traverse'' is empty test, and the rest of the test just
has the
appropriate fixture(s) to load.
The region.rb file looks like this:
class Region < ActiveRecord::Base
acts_as_tree :order => "name"
end
The fixture looks like this:
sydney_region:
id: 1
name: Sydney
country_id: 1
haymarket_region:
id: 2
name: Haymarket
country_id: 1
parent_id: 1
rocks_region:
id: 3
name: The Rocks
country_id: 1
parent_id: 1
brisbane_region:
id: 4
name: Brisbane
country_id: 1
westend_region:
id: 5
name: West End
country_id: 1
parent_id: 4
and the table def looks like this:
create table region (
id serial not null,
country_id int not null,
parent_id int null,
name varchar(50) not null,
constraint pk_region primary key (id)
);
create unique index idx_region_candidatekey on region(country_id, name);
-- edit: removed country FK
create index idx_region_parent on region(parent_id);
alter table region
add constraint fk_region_parent foreign key (parent_id)
references region(id)
;
Of course, if I remove the ''fk_region_parent'' constraint,
everything
is peachy, but I''d rather skip that if possible. I also tried
commenting out the fixture with id 5 (that is referenced in the error)
and the error just changed to refer to the one with id 2.
Anyone got any ideas?
Cheers,
Dan