3

DBIx::Class::Schema::Loaderデータベースに静的ORMを作成するために使用しています。次のメソッドを使用して作成し、ジェネリックサブをプラグインできるクラスの基本クラスResultSetを指定します。Result

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' ],
);

これは魅力のように機能しますが、基本クラスを作成する方法もわかりませんResultSource。(擬似コード)のようなことができるように、サブをそのクラスにプラグインしたいと思います。

$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;
}

ResultSource上記のようなものをプラグインできる基本クラスを使用するようにローダーに指示する方法を誰かに教えてもらえますか?

ありがとう!

4

1 に答える 1

0

これは、DBIx::class の最も理解されておらず、文書化されていない領域の 1 つです。

コンポーネントを作成し、次を使用してロードすることで実行できると思います。

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

http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/Manual/Component.podを参照してください。

于 2011-05-25T22:31:46.553 に答える