[Dbix-class] Difficulties with DBIx::Class inheritance

Rich scriptyrich at yahoo.co.uk
Sat Jun 24 18:15:47 CEST 2006


Could anyone help me get my head around how I implement a common base 
class for, and subclasses of, autogenerated DBIx::Class classes?

Going with a simple example:


    Foo::User    Foo::Project       <<< My sub classes
       |             |
       |             |
    Foo::user    Foo::project       <<< sqlt generated DBIx::Class classes
        \           /
         \         /
          \       /
           \     /
            \   /
             \ /
         Foo::Base                   <<< Common functionality


1) Foo::Base would hold common functionality for sub classes.


2) A::B::user and A::B::project would probably be defined within Foo.pm as 
autogenerated by sqlt:

  sqlt --from DBI --to DBIx::Class::File --prefix Foo --dsn DBI:mysql:foo > Foo.pm


3) Foo::User, Foo::Project would be the concrete subclasses, both adding new 
methods, and overriding methods in Foo::user, Foo::project.


So in the main code:

  use Foo;

  my $schema = Foo->connect('DBI:mysql:myapp');

  my $rs = $schema->resultset('User');     # Should get me the resultset for Foo::User

  $rs->create ....
  $rs->search ....


Normally I'd have no problems setting this up, but DBIx::Class seem a little 
more complex in the way it handles inheritance and registers classes 
and I'm not sure of the correct way to do this - I've tried a few things and I 
end up with instances of Foo::user rather than Foo::User (same with project) 
so something's clearly wrong.

I'd be really grateful if someone can tell me if this is possible (or what I 
should be doing instead) and could post an outline of how I would 
achieve this correctly using DBIx::Class. I'm happy to turn this thread
(if I get some replies) into a FAQ for the docs if that's of any use.

Many thanks,
Rich
-- 
Rich
scriptyrich at yahoo.co.uk



More information about the Dbix-class mailing list