[Catalyst] subclassing model classes

Alexander Hartmaier alexander.hartmaier at t-systems.at
Tue Dec 15 12:56:22 GMT 2009


Hi Matt!

You might want to take a look at
DBIx::Class::Schema::RestrictWithObject.

Normally I add a method to the ResultSet class of that Result class:

in ResultSet::Device:

=item search_active

Returns a resultset with all active devices.

=cut

sub search_active {
    my $self = shift;

    return $self->search_rs({
        'me.fk_monitor' => { '!=' => 3 },
    });
}

In Result::Device:

__PACKAGE__->resultset_class('NAC::Model::DBIC::ResultSet::Device');

--
Best regards, Alex


Am Dienstag, den 15.12.2009, 12:32 +0100 schrieb matthew couchman (JIC):
> Hi,
>
>
>
> I’m trying to subclass a model class so that when I search it only
> pulls out rows of a certain type. I thought that perhaps I could
> achieve that by overriding the search() function and adding a
> condition to the list of arguments as below:
>
>
>
> package MyApp::Schema::Result::Vertex;
>
>
>
> use strict;
>
> use warnings;
>
>
>
> use base 'MyApp::Schema::Result::Point';
>
>
>
> # override search
>
> sub search {
>
>     my $self = shift;
>
>     my $condition = { type => 'vertex' };
>
>     return $self->next::method($condition, @_);
>
> }
>
>
>
> 1;
>
>
>
> I don’t think that my new search function is ever called though. Do I
> need to override anything else or am I just barking up the wrong tree
> completely?
>
>
>
> Thanks for your help,
>
>
>
>                                                 Matt.
>
>
>
>
>
>


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*



More information about the Catalyst mailing list