use File::Temp 'tempfile';
use namespace::clean;
-our $VERSION = '0.07023';
+our $VERSION = '0.07032';
__PACKAGE__->mk_group_ro_accessors('simple', qw/
schema
=head2 relationship_attrs
-Hashref of attributes to pass to each generated relationship, listed
-by type. Also supports relationship type 'all', containing options to
-pass to all generated relationships. Attributes set for more specific
-relationship types override those set in 'all'.
+Hashref of attributes to pass to each generated relationship, listed by type.
+Also supports relationship type 'all', containing options to pass to all
+generated relationships. Attributes set for more specific relationship types
+override those set in 'all', and any attributes specified by this option
+override the introspected attributes of the foreign key if any.
For example:
relationship_attrs => {
- belongs_to => { is_deferrable => 0 },
+ has_many => { cascade_delete => 1, cascade_copy => 1 },
},
-use this to turn off DEFERRABLE on your foreign key constraints.
+use this to turn L<DBIx::Class> cascades to on on your
+L<has_many|DBIx::Class::Relationship/has_many> relationships, they default to
+off.
+
+Can also be a coderef, for more precise control, in which case the coderef gets
+this hash of parameters:
+
+ rel_name # the name of the relationship
+ local_source # the DBIx::Class::ResultSource object for the source the rel is *from*
+ remote_source # the DBIx::Class::ResultSource object for the source the rel is *to*
+ local_table # a DBIx::Class::Schema::Loader::Table object for the table of the source the rel is from
+ local_cols # an arrayref of column names of columns used in the rel in the source it is from
+ remote_table # a DBIx::Class::Schema::Loader::Table object for the table of the source the rel is to
+ remote_cols # an arrayref of column names of columns used in the rel in the source it is to
+ attrs # the attributes that would be set
+
+it should return the new hashref of attributes, or nothing for no changes.
+
+For example:
+
+ relationship_attrs => sub {
+ my %p = @_;
+
+ say "the relationship name is: $p{rel_name}";
+ say "the local class is: ", $p{local_source}->result_class;
+ say "the remote class is: ", $p{remote_source}->result_class;
+ say "the local table is: ", $p{local_table}->sql_name;
+ say "the rel columns in the local table are: ", (join ", ", @{$p{local_cols}});
+ say "the remote table is: ", $p{remote_table}->sql_name;
+ say "the rel columns in the remote table are: ", (join ", ", @{$p{remote_cols}});
+
+ if ($p{local_table} eq 'dogs' && @{$p{local_cols}} == 1 && $p{local_cols}[0] eq 'name') {
+ $p{attrs}{could_be_snoopy} = 1;
+
+ reutrn $p{attrs};
+ }
+ },
=head2 debug
=item * Informix, MSSQL, Sybase ASE
-C<database>, C<schema>, C<name>
+C<database>, C<schema>, C<name>
=back
'InflateColumn::DateTime',
],
}
-
+
You may use this in conjunction with L</components>.
=head2 result_roles
],
RouteChange => 'YourApp::Role::TripEvent',
}
-
+
You may use this in conjunction with L</result_roles>.
=head2 use_namespaces
Set to true to prepend the L</db_schema> to table names for C<<
__PACKAGE__->table >> calls, and to some other things like Oracle sequences.
-This attribute is automatically set to true for multi db_schema configurations.
+This attribute is automatically set to true for multi db_schema configurations,
+unless explicitly set to false by the user.
=head2 use_moose
}
$self->result_components_map($self->{result_component_map})
}
-
+
if (defined $self->{result_role_map}) {
if (defined $self->result_roles_map) {
croak "Specify only one of result_roles_map or result_role_map";
if (defined $self->db_schema) {
if (ref $self->db_schema eq 'ARRAY') {
- if (@{ $self->db_schema } > 1) {
+ if (@{ $self->db_schema } > 1 && not defined $self->{qualify_objects}) {
$self->{qualify_objects} = 1;
}
elsif (@{ $self->db_schema } == 0) {
}
}
elsif (not ref $self->db_schema) {
- if ($self->db_schema eq '%') {
+ if ($self->db_schema eq '%' && not defined $self->{qualify_objects}) {
$self->{qualify_objects} = 1;
}
# check if there are still clashes
my %by_moniker;
-
+
while (my ($t, $m) = each %new_monikers) {
- push @{ $by_moniker{$m} }, $t;
+ push @{ $by_moniker{$m} }, $t;
}
foreach my $m (grep @{ $by_moniker{$_} } > 1, keys %by_moniker) {
$self->_dump_to_dir(map { $self->classes->{$_->sql_name} } @tables);
unshift @INC, $self->dump_directory;
-
+
my @to_register;
my %have_source = map { $_ => $self->schema->source($_) }
$self->schema->sources;
for my $table (@tables) {
my $moniker = $self->monikers->{$table->sql_name};
my $class = $self->classes->{$table->sql_name};
-
+
{
no warnings 'redefine';
local *Class::C3::reinitialize = sub {}; # to speed things up, reinitialized below
my $result_base_class = $self->result_base_class || 'DBIx::Class::Core';
foreach my $src_class (@classes) {
- my $src_text =
+ my $src_text =
qq|use utf8;\n|
. qq|package $src_class;\n\n|
. qq|# Created by DBIx::Class::Schema::Loader\n|
my ($self, $version, $ts) = @_;
return qq|\n\n# Created by DBIx::Class::Schema::Loader|
. qq| v| . $version
- . q| @ | . $ts
+ . q| @ | . $ts
. qq|\n# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:|;
}
if (not $is_schema) {
return qq|\n__PACKAGE__->meta->make_immutable;|;
}
-
+
return qq|\n__PACKAGE__->meta->make_immutable(inline_constructor => 0);|;
}
elsif ($method eq 'add_unique_constraint') {
$self->_pod($class, '=head1 UNIQUE CONSTRAINTS')
unless $self->{_uniqs_started}{$class};
-
+
my ($name, $cols) = @_;
$self->_pod($class, "=head2 C<$name>");
$self->_pod($class, '=over 4');
-
+
foreach my $col (@$cols) {
$self->_pod($class, "=item \* L</$col>");
}
elsif ($method eq 'set_primary_key') {
$self->_pod($class, "=head1 PRIMARY KEY");
$self->_pod($class, '=over 4');
-
+
foreach my $col (@_) {
$self->_pod($class, "=item \* L</$col>");
}
if (my $code = $self->can('_table_comment')) {
return $self->_filter_comment($self->$code(@_));
}
-
+
return '';
}