Music Database: label -> cd -> track -> movement -> note
So, there's a hierarchy of objects.
Say, label has a "deleted" flag that always needs to be checked. So, one
option is to join and then add the check constraint in the base class:
$rs = $schema->resultset( 'Track' )->join_label->check_deleted;
$rs = $schema->resultset( 'Cd' )->join_label->check_deleted;
$rs = $schema->resultset( 'Note' )->join_label->check_deleted;
Where join_label() is a method in the specific resultset class -- e.g.
ResultSet::CD has method join_label { return shift->search( undef, { join =>
'label' } ) }, and likewise, ResultSet::Note has a join_label method that
joins from note all the way to label.
And then in the base ResultSet class check_deleted adds this to the
resultset: sub check_deleted { return shift->search( { 'label.deleted' => 0
} ); }
That works because every object is joined to the label object.
Now, assume there's also a "deleted" flag on the track object. If fetching
a CD or Label then don't want to add a track.deleted => 0 condition, but if
fetching track, movement, or a note I do want to add that condition.
Is it possible to "know" in the base "check_deleted' method that the $rs is
fetching either a track (or is joined to track) and then conditionally add
the track.deleted check?
--
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]