From: Arthur Axel 'fREW' Schmidt Date: Sun, 13 May 2012 19:15:11 +0000 (-0500) Subject: convert keys to source names X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d092eb1f8faf34c9e7843762b135d4eb596b30d3;p=dbsrgits%2FDBIx-Class.git convert keys to source names --- diff --git a/lib/DBIx/Class/Schema.pm b/lib/DBIx/Class/Schema.pm index f7dc646..3c4d9e8 100644 --- a/lib/DBIx/Class/Schema.pm +++ b/lib/DBIx/Class/Schema.pm @@ -1565,9 +1565,9 @@ sub source_tree { $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{$table_name}; + next if $tables{$moniker}; - $tables{$table_name}{source} = $source; + $tables{$moniker}{source} = $source; foreach my $rel (sort $source->relationships) { my $rel_info = $source->relationship_info($rel); @@ -1617,7 +1617,7 @@ sub source_tree { \@keys, [$source->primary_columns]); } - $tables{$table_name}{foreign_table_deps}{$rel_table}++ + $tables{$moniker}{foreign_table_deps}{$rel_table}++ if $fk_constraint && @keys # calculate dependencies: do not consider deferrable constraints and # self-references for dependency calculations diff --git a/t/schema/source-tree.t b/t/schema/source-tree.t index 5fd1bb8..f6616a5 100644 --- a/t/schema/source-tree.t +++ b/t/schema/source-tree.t @@ -8,315 +8,195 @@ use DBICTest; my $schema = DBICTest->init_schema( no_connect => 1, no_deploy => 1 ); is_deeply($schema->source_tree, { - " ( SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year\n FROM artist a\n JOIN cd ON cd.artist = a.artistid\n WHERE cd.year = ?)\n" => {}, - artist => {}, - artist_undirected_map => { + Artist => {}, + ArtistSubclass => {}, + ArtistUndirectedMap => { artist => 1 }, - artwork_to_artist => { + Artwork => { + cd => 1 + }, + Artwork_to_Artist => { artist => 1, - cd => 1, - cd_artwork => 1, - genre => 1, - track => 1 + cd_artwork => 1 }, - bindtype_test => {}, - bookmark => { + BindType => {}, + Bookmark => { link => 1 }, - books => { + BooksInLibrary => { owners => 1 }, - cd => { - genre => 1, - track => 1 - }, - cd_artwork => { - cd => 1, + CD => { genre => 1, track => 1 }, - cd_to_producer => { + CD_to_Producer => { cd => 1, - genre => 1, - producer => 1, - track => 1 + producer => 1 }, - collection => {}, - collection_object => { + Collection => {}, + CollectionObject => { collection => 1, typed_object => 1 }, - dummy => {}, - employee => { + CustomSql => {}, + Dummy => {}, + Employee => { encoded => 1 }, - encoded => {}, - event => {}, - forceforeign => { + Encoded => {}, + Event => {}, + EventTZ => {}, + ForceForeign => { artist => 1 }, - fourkeys => {}, - fourkeys_to_twokeys => { - artist => 1, - cd => 1, + FourKeys => {}, + FourKeys_to_TwoKeys => { fourkeys => 1, - genre => 1, - track => 1, twokeys => 1 }, - genre => {}, - images => { - cd => 1, - cd_artwork => 1, - genre => 1, - track => 1 + Genre => {}, + Image => { + cd_artwork => 1 }, - liner_notes => { - cd => 1, - genre => 1, - track => 1 + LinerNotes => { + cd => 1 }, - link => {}, - lyric_versions => { - cd => 1, - lyrics => 1, - track => 1 + Link => {}, + LyricVersion => { + lyrics => 1 }, - lyrics => { - cd => 1, + Lyrics => { track => 1 }, - money_test => {}, - noprimarykey => {}, - onekey => {}, - owners => {}, - producer => {}, - self_ref => {}, - self_ref_alias => { + Money => {}, + NoPrimaryKey => {}, + OneKey => {}, + Owners => {}, + Producer => {}, + SelfRef => {}, + SelfRefAlias => { self_ref => 1 }, - sequence_test => {}, - serialized => {}, - tags => { - cd => 1, - genre => 1, - track => 1 + SequenceTest => {}, + Serialized => {}, + SourceNameArtists => {}, + Tag => { + cd => 1 }, - timestamp_primary_key_test => {}, - track => { + TimestampPrimaryKey => {}, + Track => { cd => 1 }, - treelike => {}, - twokeys => { + TreeLike => {}, + TwoKeyTreeLike => {}, + TwoKeys => { artist => 1, - cd => 1, - genre => 1, - track => 1 + cd => 1 }, - twokeytreelike => {}, - typed_object => {}, + TypedObject => {} }, 'got correct source tree'); -is_deeply($schema->source_tree({ limit_sources => ['TwoKeys'] }), { - " ( SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year\n FROM artist a\n JOIN cd ON cd.artist = a.artistid\n WHERE cd.year = ?)\n" => {}, - artist => {}, - artist_undirected_map => { - artist => 1 - }, - artwork_to_artist => { - artist => 1, - cd => 1, - cd_artwork => 1, - genre => 1, - track => 1 - }, - bindtype_test => {}, - bookmark => { - link => 1 - }, - books => { - owners => 1 - }, - cd => { - genre => 1, - track => 1 - }, - cd_artwork => { - cd => 1, - genre => 1, - track => 1 - }, - cd_to_producer => { - cd => 1, - genre => 1, - producer => 1, - track => 1 - }, - collection => {}, - collection_object => { - collection => 1, - typed_object => 1 - }, - dummy => {}, - employee => { - encoded => 1 - }, - encoded => {}, - event => {}, - forceforeign => { +use Devel::Dwarn; + +my $sans_TwoKeys = { + Artist => {}, + ArtistSubclass => {}, + ArtistUndirectedMap => { artist => 1 }, - fourkeys => {}, - fourkeys_to_twokeys => { - fourkeys => 1 - }, - genre => {}, - images => { - cd => 1, - cd_artwork => 1, - genre => 1, - track => 1 - }, - liner_notes => { - cd => 1, - genre => 1, - track => 1 - }, - link => {}, - lyric_versions => { - cd => 1, - lyrics => 1, - track => 1 - }, - lyrics => { - cd => 1, - track => 1 - }, - money_test => {}, - noprimarykey => {}, - onekey => {}, - owners => {}, - producer => {}, - self_ref => {}, - self_ref_alias => { - self_ref => 1 - }, - sequence_test => {}, - serialized => {}, - tags => { - cd => 1, - genre => 1, - track => 1 - }, - timestamp_primary_key_test => {}, - track => { + Artwork => { cd => 1 }, - treelike => {}, - twokeytreelike => {}, - typed_object => {} -}, 'got correct source tree with limit_sources => [ ... ]'); - -is_deeply($schema->source_tree({ limit_sources => { TwoKeys => 1 } }), { - " ( SELECT a.*, cd.cdid AS cdid, cd.title AS title, cd.year AS year\n FROM artist a\n JOIN cd ON cd.artist = a.artistid\n WHERE cd.year = ?)\n" => {}, - artist => {}, - artist_undirected_map => { - artist => 1 - }, - artwork_to_artist => { + Artwork_to_Artist => { artist => 1, - cd => 1, - cd_artwork => 1, - genre => 1, - track => 1 + cd_artwork => 1 }, - bindtype_test => {}, - bookmark => { + BindType => {}, + Bookmark => { link => 1 }, - books => { + BooksInLibrary => { owners => 1 }, - cd => { - genre => 1, - track => 1 - }, - cd_artwork => { - cd => 1, + CD => { genre => 1, track => 1 }, - cd_to_producer => { + CD_to_Producer => { cd => 1, - genre => 1, - producer => 1, - track => 1 + producer => 1 }, - collection => {}, - collection_object => { + Collection => {}, + CollectionObject => { collection => 1, typed_object => 1 }, - dummy => {}, - employee => { + CustomSql => {}, + Dummy => {}, + Employee => { encoded => 1 }, - encoded => {}, - event => {}, - forceforeign => { + Encoded => {}, + Event => {}, + EventTZ => {}, + ForceForeign => { artist => 1 }, - fourkeys => {}, - fourkeys_to_twokeys => { + FourKeys => {}, + FourKeys_to_TwoKeys => { fourkeys => 1 }, - genre => {}, - images => { - cd => 1, - cd_artwork => 1, - genre => 1, - track => 1 + Genre => {}, + Image => { + cd_artwork => 1 }, - liner_notes => { - cd => 1, - genre => 1, - track => 1 + LinerNotes => { + cd => 1 }, - link => {}, - lyric_versions => { - cd => 1, - lyrics => 1, - track => 1 + Link => {}, + LyricVersion => { + lyrics => 1 }, - lyrics => { - cd => 1, + Lyrics => { track => 1 }, - money_test => {}, - noprimarykey => {}, - onekey => {}, - owners => {}, - producer => {}, - self_ref => {}, - self_ref_alias => { + Money => {}, + NoPrimaryKey => {}, + OneKey => {}, + Owners => {}, + Producer => {}, + SelfRef => {}, + SelfRefAlias => { self_ref => 1 }, - sequence_test => {}, - serialized => {}, - tags => { - cd => 1, - genre => 1, - track => 1 + SequenceTest => {}, + Serialized => {}, + SourceNameArtists => {}, + Tag => { + cd => 1 }, - timestamp_primary_key_test => {}, - track => { + TimestampPrimaryKey => {}, + Track => { cd => 1 }, - treelike => {}, - twokeytreelike => {}, - typed_object => {} -}, 'got correct source tree with limit_sources => { ... }'); + TreeLike => {}, + TwoKeyTreeLike => {}, + TypedObject => {} +}; + +is_deeply( + $schema->source_tree({ limit_sources => ['TwoKeys'] }), + $sans_TwoKeys, + 'got correct source tree with limit_sources => [ ... ]', +); + +is_deeply( + $schema->source_tree({ limit_sources => { TwoKeys => 1 } }), + $sans_TwoKeys, + 'got correct source tree with limit_sources => { ... }', +); # We probably also want a "collapsed" tree