简体   繁体   中英

DBIx::Class::Schema::Loader ResultSource base class

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM