Bill Moseley wrote:
Ok, get ready for a bunch of beginner questions...


What's the recommended was to setup a common base class for all the
result sources (table classes)?  A base class where I can put methods
that can be called on any table object.

Should I have each class inherit from a base class and then have that
base class inherit from DBIx::Class?  Or specify both DBIx::Class and
my base class in 'use base'?

I assume I can't use my base schema class (where I call load_classes)
as my base class as is done with CDBI.  Although that would seem a
natural place.


I looked at compose_namespace(), but I'm not clear from the docs if
that's what I need.



With CDBI I got tired or typing the same things in my table classes --
plus table classes were useful in more than on project, so I set them
up so I didn't type the namespace more than once.

So instead of:

    package My::App::Foo::Album;
    use base 'My::App::Foo';

    __PACKAGE->table( 'album' );
    __PACKAGE->has_many( tracks => 'My::App::Foo::Track' );

I just wrote:

    package My::App::Foo::Album;

    __PACKAGE__->table( 'album' );
    __PACKAGE__->has_many( tracks => 'Track' );

Where my load_classes would setup the inheritance before loading the
class, and relationship setup assumed the base class (a "+" prefix on
a class would say to not prefix it automatically).


The way I do things is;

package YourPreferences::Base::Schema::Tests::Result;

use strict;
use warnings;
use base 'DBIx::Class';

__PACKAGE__->load_components('Core');

sub table {
    my $self = shift;

    $self->next::method(@_);

    # stuff done for all classes
    # e.g.
    # $self->resultset_class('My::ResultSet');
}

1;

package YourPreferences::Schema::Tests::Foo::Result;

use strict;
use warnings;

use base 'YourPreferences::Base::Schema::Tests::Result';

__PACKAGE__->table('tests_foo_results');

# continue as normal


HTH
Ash

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to