malcolm/0000755000175000017500000000000011535352667011541 5ustar tobyctobycmalcolm/initial_sql.sql0000644000175000017500000000032611535352665014571 0ustar tobyctobyccreate table channel ( id uuid not null primary key, name text not null ); create table show ( id uuid not null primary key, channel uuid not null references channel(id), name text not null ); malcolm/test.pl0000755000175000017500000000255211535351051013046 0ustar tobyctobyc#!/usr/bin/env perl use 5.12.0; use warnings; use Malcolm::Schema; use autodie; my $schema = Malcolm::Schema->connect( 'dbi:Pg:dbname=malcolm' ); initial_data($schema) unless $schema->resultset('Channel')->search->count; # Method one (that works) { my $chan_rs = $schema->resultset('Channel')->search( { 'me.name' => 'BBC 2' } ); say "Found " . $chan_rs->count. " channel(s)."; my $show_rs = $chan_rs->search_related('shows'); say "Found " . $show_rs->count . " shows."; } # Method two (that works) { my $chan_rs = $schema->resultset('Channel')->search( { name => 'BBC 2' } ); say "Found " . $chan_rs->count. " channel(s)."; my $show_rs = $chan_rs->as_subselect_rs->search_related('shows'); say "Found " . $show_rs->count . " shows."; } sub initial_data { my $schema = shift; my $chan = $schema->resultset('Channel')->create( { id => new_uuid(), name => 'BBC 2', } ); map { $schema->resultset('Show')->create( { id => new_uuid(), name => $_, channel => $chan->id, } ); } ('Top Gear', 'Never mind the Buzzcocks', 'QI'); return; } sub new_uuid { open my $fh, '/proc/sys/kernel/random/uuid'; my $uuid = <$fh>; close $fh; chomp $uuid; return $uuid; } malcolm/Malcolm/0000755000175000017500000000000011535346201013110 5ustar tobyctobycmalcolm/Malcolm/Schema.pm0000644000175000017500000000017011535345652014655 0ustar tobyctobycpackage Malcolm::Schema; use strict; use warnings; use parent 'DBIx::Class::Schema'; __PACKAGE__->load_namespaces; 1; malcolm/Malcolm/Schema/0000755000175000017500000000000011535345712014316 5ustar tobyctobycmalcolm/Malcolm/Schema/Result/0000755000175000017500000000000011535352530015570 5ustar tobyctobycmalcolm/Malcolm/Schema/Result/Channel.pm0000644000175000017500000000051411535350335017477 0ustar tobyctobycpackage Malcolm::Schema::Result::Channel; use strict; use warnings; use parent 'DBIx::Class'; __PACKAGE__->load_components(qw(Core)); __PACKAGE__->table('channel'); __PACKAGE__->add_columns(qw(id name)); __PACKAGE__->set_primary_key('id'); __PACKAGE__->has_many( shows => 'Malcolm::Schema::Result::Show', 'channel' ); 1; malcolm/Malcolm/Schema/Result/Show.pm0000644000175000017500000000050511535350232017043 0ustar tobyctobycpackage Malcolm::Schema::Result::Show; use strict; use warnings; use parent 'DBIx::Class'; __PACKAGE__->load_components(qw(Core)); __PACKAGE__->table('show'); __PACKAGE__->add_columns(qw(id channel name)); __PACKAGE__->set_primary_key('id'); __PACKAGE__->belongs_to( channel => 'Malcolm::Schema::Result::Channel' ); 1;