- Fix incorrect error detection during populate() on Oracle
- Better handling of result_source-less row objects by
auto-calling result_source_instance when necessary
+ - Fix reverse_relationship_info and sqlt deploy on partially
+ loaded schemas (relationships point to non-existent sources)
0.08126_01 2011-01-14 14:00 (UTC)
* New Features / Changes
my @otherrels = $othertable->relationships();
my $otherrelationship;
foreach my $otherrel (@otherrels) {
- my $otherrel_info = $othertable->relationship_info($otherrel);
+ # this may be a partial schema with the related source not being
+ # available at all
+ my $back = try { $othertable->related_source($otherrel) } or next;
- my $back = $othertable->related_source($otherrel);
+ # did we get back to ourselves?
next unless $back->source_name eq $self->source_name;
+ my $otherrel_info = $othertable->relationship_info($otherrel);
my @othertestconds;
if (ref $otherrel_info->{cond} eq 'HASH') {
croak 'No DBIx::Class::Schema' unless ($dbicschema);
if (!ref $dbicschema) {
- try {
- eval "require $dbicschema;"
- }
- catch {
- croak "Can't load $dbicschema ($_)";
- }
+ eval "require $dbicschema"
+ or croak "Can't load $dbicschema: $@";
}
my $schema = $tr->schema;
# Ignore any rel cond that isn't a straight hash
next unless ref $rel_info->{cond} eq 'HASH';
- my $relsource = $source->related_source($rel);
+ my $relsource = try { $source->related_source($rel) };
+ unless ($relsource) {
+ warn "Ignoring relationship '$rel' - related resultsource '$rel_info->{class}' is not registered with this schema\n";
+ next;
+ };
# related sources might be excluded via a {sources} filter or might be views
next unless exists $table_monikers{$relsource->source_name};
# the hook might have already removed the table
if ($schema->get_table($table) && $table =~ /^ \s* \( \s* SELECT \s+/ix) {
- warn <<'EOW';
+ carp <<'EOW';
Custom SQL through ->name(\'( SELECT ...') is DEPRECATED, for more details see
"Arbitrary SQL through a custom ResultSource" in DBIx::Class::Manual::Cookbook
});
+{
+ package DBICTest::PartialSchema;
+
+ use base qw/DBIx::Class::Schema/;
+
+ __PACKAGE__->load_classes(
+ { 'DBICTest::Schema' => [qw/
+ CD
+ Track
+ Tag
+ Producer
+ CD_to_Producer
+ /]}
+ );
+}
+
+{
+ my $partial_schema = DBICTest::PartialSchema->connect(DBICTest->_database);
+
+ lives_ok (sub {
+ my $sqlt_schema = do {
+
+ local $SIG{__WARN__} = sub {
+ warn @_
+ unless $_[0] =~ /Ignoring relationship .+ related resultsource .+ is not registered with this schema/
+ };
+
+ create_schema({ schema => $partial_schema });
+ };
+
+ my @tables = $sqlt_schema->get_tables;
+
+ is_deeply (
+ [sort map { $_->name } @tables],
+ [qw/cd cd_to_producer producer tags track/],
+ 'partial dbic schema parsing ok',
+ );
+
+ # the primary key is currently unnamed in sqlt - adding below
+ my %constraints_for_table = (
+ producer => [qw/prod_name /],
+ tags => [qw/tagid_cd tagid_cd_tag tags_fk_cd tags_tagid_tag tags_tagid_tag_cd /],
+ track => [qw/track_cd_position track_cd_title track_fk_cd /],
+ cd => [qw/cd_artist_title cd_fk_single_track /],
+ cd_to_producer => [qw/cd_to_producer_fk_cd cd_to_producer_fk_producer /],
+ );
+
+ for my $table (@tables) {
+ my $tablename = $table->name;
+ my @constraints = $table->get_constraints;
+ is_deeply (
+ [ sort map { $_->name } @constraints ],
+
+ # the primary key (present on all loaded tables) is currently named '' in sqlt
+ # subject to future changes
+ [ '', @{$constraints_for_table{$tablename}} ],
+
+ "constraints of table '$tablename' ok",
+ );
+ }
+ }, 'partial schema tests successful');
+}
+
done_testing;
sub create_schema {