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.
So in the Cd class I add:
Cd->has_many( pending_tracks => 'App::Track::Pending', { 'foreign.cd' => '
self.id' } );
sub pending_tracks { shift->pending_tracks( { pending => 1 } ) }
I tried the naive approach of just subclassing Track. Then I tried
using DBIx::Class::Helper::Row::SubClass:
package App::Result::Track::Pending;
use parent 'App::Result::Track';
__PACKAGE__->load_components(qw{Helper::Row::SubClass Core});
__PACKAGE__->subclass;
1;
But, then when I call $cd->pending_tracks I get:
DBIx::Class::Schema::throw_exception(): Namespaces
App::Result::Track::Pending and App::Result::Studio are dissimilar at
/usr/local/share/perl/5.10.0/DBIx/Class/Helpers/Util.pm line 43.
Which I assume is because there's a Track->belongs_to( studio =>
'App::Result::Studio' ) but in ::Studio there's a has_many to Track but not
to Track::Pending.
Can someone help out with an example of how this is suppose to be done?
Thanks,
--
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]