I have an existing set of schema and result classes used by an application.
  I now need to provide access to another very similar database that has a
sub-set of tables and where table names are renamed and some tables are
missing some columns.  But, I want to share my existing result and resultSet
methods, with the ability to override as needed.

I'd like to check that my approach is sane.

Currently I have my schema class, App::DB that only contains a call to
load_namespaces( default_resultset_class => 'ResultSet' ), and inherits from
App::DB::Base which has some additional schema methods.  App::DB::Base
inherits from DBIx::Class::Schema.

I've created a new schema class, New::DB that also
calls __PACKAGE__->load_namespaces but it also inherits from App::DB::Base;


I then have New::DB::ResultSet.pm that inherits from App::DB::ResultSet so
those methods are shared.  I can add, say, New::DB::ResultSet::User if I
need to override, for example.

All this works fine.

The question I have is about my result classes.   My Result class "User"
inherits from App::DB::Result which inherits from DBIx::Class;

My existing result classes have additional row methods, for example
something like this in my App::DB::Result::User class:

sub full_name {
    my $self = shift;
    return join ' ', $self->first_name, $self->last_name;
}

I want to share those methods between my two result classes (i.e.
App::DB::Result::User and New::DB::Result::User).  I'm thinking the only way
to do that is with a role because my new class New::DB::Result::User needs
to inherit from New::DB::Result and that inherits from App::DB::Result.

Is there another way to do this?  Or does this seem like the correct
approach?

BTW -- I'm currently using App::DB::ResultRole::User for result roles.  I
assume that's as good of place as any.



-- 
Bill Moseley
[email protected]
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]

Reply via email to