[Catalyst] subclassing model classes
matthew couchman (JIC)
matthew.couchman at bbsrc.ac.uk
Tue Dec 15 17:58:52 GMT 2009
Hi Alex,
Thanks for your reply and thanks to Wallace as well as apologies for mailing the wrong group. I think I have a clearer idea of how things are working now so your help is very much appreciated. I have a follow up question which I hope you don't mind me posting here for completeness.
I now have a couple of subclasses of Point called Vertex and Placemark. I'm trying to associate them with my new ResultSet subclasses.
In MyApp::Schema::Result::Vertex:
use base 'MyApp::Schema::Result::Point';
__PACKAGE__->resultset_class('MyApp::Schema::ResultSet::Vertex');
And in MyApp::Schema::Result::Placemark:
use base 'MyApp::Schema::Result::Point';
__PACKAGE__->resultset_class('MyApp::Schema::ResultSet::Placemark');
I think __PACKAGE__->resultset_class is calling the parent class MyApp::Schema::Result::Point->resultset_class in both cases so the second call overwrites the first. How do I avoid this?
Many thanks again for your help,
Matt.
> -----Original Message-----
> From: Alexander Hartmaier [mailto:alexander.hartmaier at t-systems.at]
> Sent: 15 December 2009 12:56
> To: The elegant MVC web framework
> Subject: Re: [Catalyst] subclassing model classes
>
> 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.
> *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
> "*"*"*
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-
> archive.com/catalyst at lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
More information about the Catalyst
mailing list