Home > Software design >  DBIx::Class::Schema::Loader ResultSource base class
DBIx::Class::Schema::Loader ResultSource base class

Time:11-15

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!

CodePudding user response:

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

CodePudding user response:

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.

  • Related