3

I am using DBIx::Class::Schema::Loader for creating a static ORM to my database. I use the following method to create it and specify base classes for ResultSet and Result classes which I can plug generic subs into:

make_schema_at(
'MyApp::Schema',
{ 
    debug => 1, 
    dump_directory => '/home/rob/projects/myapp/MyApp/lib',
    overwrite_modifications => 1, 
    components=> ['EncodedColumn'],
    use_namespaces          => 1,
    result_base_class       => 'MyApp::Schema::ResultBase',
    default_resultset_class => 'ResultSetBase'
},
[ 'DBI:mysql:database=mydb;host=localhost;port=3306','user', 'pass' ],
);

This works like a charm, but I cannot find out how to create a base class for ResultSource as well. I would like to plug a sub into that class such that I can do something like (pseudo code):

$c->model('DB')->source->('Account')->getParentSource('Project');

ResultSourceBase.pm:

sub getParentSource {
     my ($self,$parent) = @_;
     foreach $relation in $self->relations
         if ($relation->identifier eq  $parent)
             return $relation->source;

     return $self;
}

Can anyone tell me how to tell the loader to use a base ResultSource class in which I can plug things like the above into?

Thanks!

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Rob Boerman
  • 2,148
  • 14
  • 21

2 Answers2

0

This is one of the least understood and poorly documented areas of DBIx::class.

I think you can do it by creating a component and loading it using:

__PACKAGE__->load_components(qw/ +My::Component /);

See http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/Manual/Component.pod

Tom
  • 2,416
  • 3
  • 31
  • 38
0

The inheritance architecture of DBIX::Class is indeed very complex.
I did some research into it in 2012; slide 43 of https://www.slideshare.net/ldami/dbixclass-vs-dbixdatamodel may be of some help to understand the global picture.

dami
  • 146
  • 8