return $schema;
}
+sub r_sources {
+ my $self = shift;
+
+ my %sref = %{$self->source_registrations};
+
+ return {
+ map { $sref{$_} => $_ } keys %sref
+ }
+}
+
sub source_tree {
my $self = shift;
my $args = shift;
grep { !$limit_sources{$_} }
$self->sources;
- my %tables;
+ my %r_sources = %{$self->r_sources};
+ my %sources;
foreach my $moniker (sort keys %table_monikers) {
my $source = $self->source($moniker);
- my $table_name = $source->name;
-
- # FIXME - this isn't the right way to do it, but sqlt does not
- # support quoting properly to be signaled about this
- $table_name = $$table_name if ref $table_name eq 'SCALAR';
# It's possible to have multiple DBIC sources using the same table
- next if $tables{$moniker};
+ next if $sources{$moniker};
- $tables{$moniker}{source} = $source;
+ $sources{$moniker}{source} = $source;
foreach my $rel (sort $source->relationships) {
my $rel_info = $source->relationship_info($rel);
# related sources might be excluded via a {sources} filter or might be views
next unless exists $table_monikers{$relsource->source_name};
- my $rel_table = $relsource->name;
-
- # FIXME - this isn't the right way to do it, but sqlt does not
- # support quoting properly to be signaled about this
- $rel_table = $$rel_table if ref $rel_table eq 'SCALAR';
+ my $rel_moniker = $r_sources{$relsource};
# Force the order of @cond to match the order of ->add_columns
my $idx;
\@keys, [$source->primary_columns]);
}
- $tables{$moniker}{foreign_table_deps}{$rel_table}++
+ $sources{$moniker}{foreign_table_deps}{$rel_moniker}++
if $fk_constraint && @keys
# calculate dependencies: do not consider deferrable constraints and
# self-references for dependency calculations
&& !$rel_info->{attrs}{is_deferrable}
- && $rel_table && $rel_table ne $table_name
+ && $rel_moniker && $rel_moniker ne $moniker
}
}
return {
- map { $_ => $self->_resolve_deps ($_, \%tables) } (keys %tables)
+ map { $_ => $self->_resolve_deps ($_, \%sources) } (keys %sources)
}
}
my $schema = DBICTest->init_schema( no_connect => 1, no_deploy => 1 );
+use Devel::Dwarn;
+
is_deeply($schema->source_tree, {
Artist => {},
ArtistSubclass => {},
ArtistUndirectedMap => {
- artist => 1
+ Artist => 1
},
Artwork => {
- cd => 1
+ CD => 1,
+ Genre => 1,
+ Track => 1
},
Artwork_to_Artist => {
- artist => 1,
- cd_artwork => 1
+ Artist => 1,
+ Artwork => 1,
+ CD => 1,
+ Genre => 1,
+ Track => 1
},
BindType => {},
Bookmark => {
- link => 1
+ Link => 1
},
BooksInLibrary => {
- owners => 1
+ Owners => 1
},
CD => {
- genre => 1,
- track => 1
+ Genre => 1,
+ Track => 1
},
CD_to_Producer => {
- cd => 1,
- producer => 1
+ CD => 1,
+ Genre => 1,
+ Producer => 1,
+ Track => 1
},
Collection => {},
CollectionObject => {
- collection => 1,
- typed_object => 1
+ Collection => 1,
+ TypedObject => 1
},
CustomSql => {},
Dummy => {},
Employee => {
- encoded => 1
+ Encoded => 1
},
Encoded => {},
Event => {},
EventTZ => {},
ForceForeign => {
- artist => 1
+ Artist => 1
},
FourKeys => {},
FourKeys_to_TwoKeys => {
- fourkeys => 1,
- twokeys => 1
+ Artist => 1,
+ CD => 1,
+ FourKeys => 1,
+ Genre => 1,
+ Track => 1,
+ TwoKeys => 1
},
Genre => {},
Image => {
- cd_artwork => 1
+ Artwork => 1,
+ CD => 1,
+ Genre => 1,
+ Track => 1
},
LinerNotes => {
- cd => 1
+ CD => 1,
+ Genre => 1,
+ Track => 1
},
Link => {},
LyricVersion => {
- lyrics => 1
+ CD => 1,
+ Lyrics => 1,
+ Track => 1
},
Lyrics => {
- track => 1
+ CD => 1,
+ Track => 1
},
Money => {},
NoPrimaryKey => {},
Producer => {},
SelfRef => {},
SelfRefAlias => {
- self_ref => 1
+ SelfRef => 1
},
SequenceTest => {},
Serialized => {},
SourceNameArtists => {},
Tag => {
- cd => 1
+ CD => 1,
+ Genre => 1,
+ Track => 1
},
TimestampPrimaryKey => {},
Track => {
- cd => 1
+ CD => 1
},
TreeLike => {},
TwoKeyTreeLike => {},
TwoKeys => {
- artist => 1,
- cd => 1
+ Artist => 1,
+ CD => 1,
+ Genre => 1,
+ Track => 1
},
TypedObject => {}
}, 'got correct source tree');
Artist => {},
ArtistSubclass => {},
ArtistUndirectedMap => {
- artist => 1
+ Artist => 1
},
Artwork => {
- cd => 1
+ CD => 1,
+ Genre => 1,
+ Track => 1
},
Artwork_to_Artist => {
- artist => 1,
- cd_artwork => 1
+ Artist => 1,
+ Artwork => 1,
+ CD => 1,
+ Genre => 1,
+ Track => 1
},
BindType => {},
Bookmark => {
- link => 1
+ Link => 1
},
BooksInLibrary => {
- owners => 1
+ Owners => 1
},
CD => {
- genre => 1,
- track => 1
+ Genre => 1,
+ Track => 1
},
CD_to_Producer => {
- cd => 1,
- producer => 1
+ CD => 1,
+ Genre => 1,
+ Producer => 1,
+ Track => 1
},
Collection => {},
CollectionObject => {
- collection => 1,
- typed_object => 1
+ Collection => 1,
+ TypedObject => 1
},
CustomSql => {},
Dummy => {},
Employee => {
- encoded => 1
+ Encoded => 1
},
Encoded => {},
Event => {},
EventTZ => {},
ForceForeign => {
- artist => 1
+ Artist => 1
},
FourKeys => {},
FourKeys_to_TwoKeys => {
- fourkeys => 1
+ FourKeys => 1
},
Genre => {},
Image => {
- cd_artwork => 1
+ Artwork => 1,
+ CD => 1,
+ Genre => 1,
+ Track => 1
},
LinerNotes => {
- cd => 1
+ CD => 1,
+ Genre => 1,
+ Track => 1
},
Link => {},
LyricVersion => {
- lyrics => 1
+ CD => 1,
+ Lyrics => 1,
+ Track => 1
},
Lyrics => {
- track => 1
+ CD => 1,
+ Track => 1
},
Money => {},
NoPrimaryKey => {},
Producer => {},
SelfRef => {},
SelfRefAlias => {
- self_ref => 1
+ SelfRef => 1
},
SequenceTest => {},
Serialized => {},
SourceNameArtists => {},
Tag => {
- cd => 1
+ CD => 1,
+ Genre => 1,
+ Track => 1
},
TimestampPrimaryKey => {},
Track => {
- cd => 1
+ CD => 1
},
TreeLike => {},
TwoKeyTreeLike => {},
'got correct source tree with limit_sources => { ... }',
);
-# We probably also want a "collapsed" tree
+# We probably also want a "collapsed" tree thingy
done_testing;