}
}
+method _source_by_name ($name) {
+ my $schema = $self->schema;
+ my ($source) =
+ grep { $_->name eq $name }
+ map $schema->source($_), $schema->sources;
+ confess "Couldn't find attached source for parent $name - did you use load_classes? This module is only compatible with load_namespaces"
+ unless $source;
+ return $source;
+}
+
method schema (@args) {
my $ret = $self->next::method(@args);
if (@args) {
if ($self->parent_source) {
- my $schema = $self->schema;
my $parent_name = $self->parent_source->name;
- my ($parent) =
- grep { $_->name eq $parent_name }
- map $schema->source($_), $schema->sources;
- confess "Couldn't find attached source for parent $parent_name - did you use load_classes? This module is only compatible with load_namespaces"
- unless $parent;
- $self->parent_source($parent); # so our parent is the one in this schema
+ $self->parent_source($self->_source_by_name($parent_name));
}
+ $self->additional_parents([
+ map { $self->_source_by_name($_->name) }
+ @{$self->additional_parents||[]}
+ ]);
}
return $ret;
}
BEGIN { use_ok 'MTITest'; }
-warn MTITest->sources;
-
my $raw_foo = MTITest->source('Raw::Foo');
is_deeply(
use strict;
use warnings;
use lib 't/lib';
+use File::Temp;
use Test::More qw(no_plan);
use Test::Exception;
use Data::Dumper; $Data::Dumper::Indent = 1;
my $schema = MTITest->connect('dbi:SQLite::memory:');
-warn $schema->source($_)->view_definition for qw(Foo Bar);
+my $dir = "t/sql"; # tempdir(CLEANUP => 0);
+
+$schema->create_ddl_dir([ 'PostgreSQL' ], 0.1, $dir);
+
+#warn $schema->source($_)->view_definition for qw(Foo Bar);
+#use Data::Dumper; $Data::Dumper::Indent = 1;
+#warn Dumper($schema->source($_)) for qw(Foo Bar);
use warnings;
use parent qw(MTITest::Result::Foo);
+require MTITest::Result::Mixin;
+
__PACKAGE__->table('bar');
+__PACKAGE__->result_source_instance->add_additional_parent(
+ MTITest::Result::Mixin->result_source_instance
+);
+
__PACKAGE__->add_columns(
b => { data_type => 'integer' }
);
__PACKAGE__->add_columns(
id => { data_type => 'integer', is_auto_increment => 1 },
- a => { data_type => 'integer' }
+ a => { data_type => 'integer', is_nullable => 1 }
);
__PACKAGE__->set_primary_key('id');
--- /dev/null
+package MTITest::Result::Mixin;
+
+use strict;
+use warnings;
+use parent qw(DBIx::Class::Core);
+
+__PACKAGE__->table('mixin');
+
+__PACKAGE__->add_columns(
+ id => {
+ data_type => 'integer', is_auto_increment => 1, sequence => 'foo_id_seq'
+ },
+ words => { data_type => 'text' }
+);
+
+__PACKAGE__->set_primary_key('id');
+
+1;