On Tue, Apr 27, 2010 at 00:46, Bill Moseley <[email protected]> wrote:
> I want to create separate Result classes for basically the same objects --
> same columns and methods, plus a few methods specific to the new sub-class.
> In my music database I have Cd objects and Track objects.  The Track objects
> have a "pending" flag (for lack of a better example).
> In my Cd Result class I have Cd->has_many( tracks => 'App::Track' ); and,
> thus, I can call $cd->tracks;
> Now, say I want to have $cd->pending_tracks, which is easy:
> sub pending_tracks {   shift->tracks({ pending => 1 }} }
> But, what if I want $cd->pending_tracks->all to return
> App::Result::Track::Pending objects, where Track::Pending objects is really
> just a subclass of the Track class? The reason I want to do this is so I can
> have methods specific to just pending tracks.

sub pending_tracks {
    my $self = shift;
    my $rs = $self->tracks({ pending => 1 });
    $rs->result_class( 'My::App::Track::Pending' );
    return $rs;
}

Rob

_______________________________________________
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