TMPDIR => 1,
CLEANUP => 1,
);
+ $self->_check_back_compat;
+ $self;
+}
- $self->{relbuilder} = DBIx::Class::Schema::Loader::RelBuilder->new(
- $self->schema, $self->inflect_plural, $self->inflect_singular
- ) if !$self->{skip_relationships};
+sub _check_back_compat {
+ my ($self) = @_;
- $self;
+ my $filename = $self->_get_dump_filename($self->schema_class);
+ return unless -e $filename;
+
+ open(my $fh, '<', $filename)
+ or croak "Cannot open '$filename' for reading: $!";
+
+ while (<$fh>) {
+ if (/^# Created by DBIx::Class::Schema::Loader (v\d+)\.(\d+)/) {
+ my $ver = "${1}_${2}";
+ while (1) {
+ my $compat_class = "DBIx::Class::Schema::Loader::Compat::${ver}";
+ if ($self->load_optional_class($compat_class)) {
+ no strict 'refs';
+ my $class = ref $self || $self;
+ unshift @{"${class}::ISA"}, $compat_class;
+ last;
+ }
+ $ver =~ s/\d\z// or last;
+ }
+ last;
+ }
+ }
+ close $fh;
}
sub _find_file_in_inc {
my ($self, $schema) = @_;
$self->{schema} = $schema;
- $self->{relbuilder}{schema} = $schema;
+ $self->_relbuilder->{schema} = $schema;
my @created;
my @current = $self->_tables_list;
return map { $self->monikers->{$_} } @$loaded;
}
+sub _relbuilder {
+ my ($self) = @_;
+ $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder->new(
+ $self->schema, $self->inflect_plural, $self->inflect_singular
+ );
+}
+
sub _load_tables {
my ($self, @tables) = @_;
my $tbl_uniq_info = $self->_table_uniq_info($table);
my $local_moniker = $self->monikers->{$table};
- my $rel_stmts = $self->{relbuilder}->generate_code($local_moniker, $tbl_fk_info, $tbl_uniq_info);
+ my $rel_stmts = $self->_relbuilder->generate_code($local_moniker, $tbl_fk_info, $tbl_uniq_info);
foreach my $src_class (sort keys %$rel_stmts) {
my $src_stmts = $rel_stmts->{$src_class};
--- /dev/null
+package DBIx::Class::Schema::Loader::Compat::v0_040;
+
+use strict;
+use warnings;
+use Class::C3;
+use DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040;
+
+# Make a moniker from a table
+sub _default_table2moniker {
+ my ($self, $table) = @_;
+
+ return join '', map ucfirst, split /[\W_]+/, lc $table;
+}
+
+sub _relbuilder {
+ my ($self) = @_;
+ $self->{relbuilder} ||= DBIx::Class::Schema::Loader::RelBuilder::v04Compat->new(
+ $self->schema, $self->inflect_plural, $self->inflect_singular
+ );
+}
+
+1;
--- /dev/null
+package DBIx::Class::Schema::Loader::RelBuilder::Compat::v0_040;
+
+use strict;
+use warnings;
+use Class::C3;
+
+use base 'DBIx::Class::Schema::Loader::RelBuilder';
+
+sub _uniq_fk_rel {
+ my ($self, $local_moniker, $local_relname, $local_cols, $uniqs) = @_;
+
+ return ('has_many', $local_relname);
+}
+
+sub _remote_attrs { }
+
+sub _remote_relname {
+ my ($self, $remote_table, $cond) = @_;
+
+ my $remote_relname;
+ # for single-column case, set the remote relname to the column
+ # name, to make filter accessors work
+ if(scalar keys %{$cond} == 1) {
+ $remote_relname = $self->_inflect_singular(values %{$cond});
+ }
+ else {
+ $remote_relname = $self->_inflect_singular(lc $remote_table);
+ }
+
+ return $remote_relname;
+}
+
+
+1;