[Dbix-class] inject_base doesn't affect related resultset/resultsource

Mario Minati mario.minati at googlemail.com
Fri Dec 21 09:48:44 GMT 2007


Hi,

I still have trouble with my inject class. Here is what I do in my Catalyst 
app:

############
package glueDB::Contact::Company;

__PACKAGE__->load_components(
    qw/
        glue::Historic
	...
        Core
        /
);

__PACKAGE__->has_many(
    branches => 'glueDB::Contact::Company::Branch',
    'company_id',
    { cascade_delete => 0 }
);

__PACKAGE__->load_historic;

############
package glueDB::Contact::Branch

__PACKAGE__->load_components(
    qw/
        glue::Historic
	...
        Core
        /
);

__PACKAGE__->belongs_to(
    company => 'glueDB::Contact::Company',
    'company_id',
    { cascade_delete => 0 }
);

__PACKAGE__->load_historic;

#############
package DBIx::Class::glue::Historic;
sub load_historic {
    my ( $class ) = @_;
    $result_source_instance = $class->result_source_instance();
    $source_class = ref($result_source_instance);
        glueDB->inject_base(
            join('::', $source_class, '__HistoricResultset'),
            'DBIx::Class::glue::Historic::RestrictResultset',
            $source_class
        );
}

##############
package DBIx::Class::glue::Historic::RestrictResultset;
sub resultset {
    my $self = shift;
    $rs = $self->next::method(@_);
warn ref $rs;
    return $rs;
}

##############

When I get a company object 
$company = $c->model( 'glueDB::Contact::Company' )->search(id=>1);
the 'warn' in  DBIx::Class::glue::Historic::RestrictResultset gets called as 
expected.

BUT:
If I do
$branch = $company->branch;
it doesn't get called anymore.

Could some explain me why this doesn't work as I also injected my own 
baseclass (DBIx::Class::glue::Historic::RestrictResultset;) into it's @ISA.

Any tips are very welcome.

Greets,
Mario



More information about the DBIx-Class mailing list