7 use DBIx::Class::Schema::Loader 0.05;
8 use Data::Dumper::Concise;
11 package CPANDB::Schema;
12 use base qw/DBIx::Class::Schema::Loader/;
14 __PACKAGE__->loader_options (
19 my $s = CPANDB::Schema->connect (sub { CPANDB->dbh } );
21 # reference names are unstable - just create rels manually
22 my $distrsrc = $s->source('Distribution');
24 # the has_many helper is a class-only method (why?), thus
26 $distrsrc->add_relationship (
28 $s->class('Dependency'),
29 { 'foreign.distribution' => 'self.' . ($distrsrc->primary_columns)[0] },
30 { accessor => 'multi', join_type => 'left' },
33 # here is how one could use the helper currently:
35 #my $distresult = $s->class('Distribution');
36 #$distresult->has_many (
38 # $s->class('Dependency'),
41 #$s->unregister_source ('Distribution');
42 #$s->register_class ('Distribution', $distresult);
45 # a proof of concept how to find out who uses us *AND* SQLT
46 my $us_and_sqlt = $s->resultset('Distribution')->search (
48 'deps.dependency' => 'DBIx-Class',
49 'deps_2.dependency' => 'SQL-Translator',
52 join => [qw/deps deps/],
53 order_by => 'me.author',
54 select => [ 'me.distribution', 'me.author', map { "$_.phase" } (qw/deps deps_2/)],
55 as => [qw/dist_name dist_author req_dbic_at req_sqlt_at/],
56 result_class => 'DBIx::Class::ResultClass::HashRefInflator',
60 print Dumper [$us_and_sqlt->all];