until the end of the transaction. Currently, only the PostgreSQL producer
actually supports this.
+=item add_fk_index
+
+Tells L<SQL::Translator> to add an index for this constraint. Can also be
+specified globally in the args to L<DBIx::Class::Schema/deploy> or
+L<DBIx::Class::Schema/create_ddl_dir>. Default is on, set to 0 to disable.
+
=back
=head2 register_relationship
my @rels = $source->relationships();
my %created_FK_rels;
+
+ # global add_fk_index set in parser_args
+ my $add_fk_index = (exists $args->{add_fk_index} && ($args->{add_fk_index} == 0)) ? 0 : 1;
foreach my $rel (sort @rels)
{
}
my $is_deferrable = $rel_info->{attrs}{is_deferrable};
+
+ # global parser_args add_fk_index param can be overridden on the rel def
+ my $add_fk_index_rel = (exists $rel_info->{attrs}{add_fk_index}) ? $rel_info->{attrs}{add_fk_index} : $add_fk_index;
# Make sure we dont create the same foreign key constraint twice
my $key_test = join("\x00", @keys);
(defined $is_deferrable ? ( deferrable => $is_deferrable ) : ()),
);
- unless (exists $args->{add_fk_index} && ($args->{add_fk_index} == 0)) {
+ if ($add_fk_index_rel) {
my $index = $table->add_index(
name => join('_', $table->name, 'idx', @keys),
fields => \@keys,
my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
my @indices = $table->get_indices;
my $index_count = scalar(@indices);
+ $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
is($index_count, $fk_count, "correct number of indices for $source with no args");
}
}
my $fk_count = scalar(grep { $_->type eq 'FOREIGN KEY' } $table->get_constraints);
my @indices = $table->get_indices;
my $index_count = scalar(@indices);
+ $index_count++ if ($source eq 'TwoKeys'); # TwoKeys has the index turned off on the rel def
is($index_count, $fk_count, "correct number of indices for $source with add_fk_index => 1");
}
}
__PACKAGE__->set_primary_key(qw/artist cd/);
__PACKAGE__->belongs_to( artist => 'DBICTest::Schema::Artist' );
-__PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, { is_deferrable => 0 } );
+__PACKAGE__->belongs_to( cd => 'DBICTest::Schema::CD', undef, { is_deferrable => 0, add_fk_index => 0 } );
__PACKAGE__->has_many(
'fourkeys_to_twokeys', 'DBICTest::Schema::FourKeys_to_TwoKeys', {