10 package DBICTest::ArtistRS;
13 use base qw/DBIx::Class::ResultSet/;
16 my $schema = DBICTest->init_schema();
17 my $artist_source = $schema->source('Artist');
19 my $new_source = DBIx::Class::ResultSource::Table->new({
21 name => 'artist_preview',
22 resultset_class => 'DBICTest::ArtistRS',
23 _relationships => {}, # copying them as-is is bad taste
25 $new_source->add_column('other_col' => { data_type => 'integer', default_value => 1 });
28 $schema->register_extra_source( 'artist->extra' => $new_source );
30 my $primary_source = $schema->source('DBICTest::Artist');
31 is($primary_source->source_name, 'Artist', 'original source still primary source');
32 ok(! $primary_source->has_column('other_col'), 'column definition did not leak to original source');
33 isa_ok($schema->resultset ('artist->extra'), 'DBICTest::ArtistRS');
37 my $source = $schema->source('DBICTest::Artist');
38 $schema->register_source($source->source_name, $source);
39 }, [], 're-registering an existing source under the same name causes no warnings' );
43 my $new_source_name = 'Artist->preview(artist_preview)';
44 $schema->register_source( $new_source_name => $new_source );
46 my $primary_source = $schema->source('DBICTest::Artist');
47 is($primary_source->source_name, $new_source_name, 'new source is primary source');
48 ok($primary_source->has_column('other_col'), 'column correctly defined on new source');
50 isa_ok ($schema->resultset ($new_source_name), 'DBICTest::ArtistRS');
52 my $original_source = $schema->source('Artist');
53 ok(! $original_source->has_column('other_col'), 'column definition did not leak to original source');
54 isa_ok ($original_source->resultset, 'DBIx::Class::ResultSet');
55 isa_ok ($schema->resultset('Artist'), 'DBIx::Class::ResultSet');
58 qr/DBICTest::Artist already has a source, use register_extra_source for additional sources/
60 'registering source to an existing result warns'