On Tue, Apr 27, 2010 at 6:28 AM, Rob Kinyon <[email protected]> wrote:
>
> sub pending_tracks {
> my $self = shift;
> my $rs = $self->tracks({ pending => 1 });
> $rs->result_class( 'My::App::Track::Pending' );
> return $rs;
> }
>
Thanks, I think I was confused by Helper::Row::SubClass I'm curious how
that differs from the inflate_result example in the Cookbook? When would
one be used over the other?
Now, a related question. The FAQ describes how to store non-database data
in the class. What I'm not clear on is how to set the data per instance
when using the above method.
A different example might help explain:
For example, say I have a database for managing conferences. At a
conference Attendees sign up for one or more Sessions as a typical
many-to-many relationship.
I can get Attendees for a given session: my $session_attendees =
$session->attendees;
For a give attendee (found via a Session) I'd like that Attendee object to
"know" what session it came from.
Say another many-to-many relationship exists -- each Attendee writes a
review of each Session they attend.
In other words,
$schema->resultset( 'Attendee' )->first->reviews; # returns reviews for ALL
sessions attended by the first attendee.
But,
$session_attendee = $session->attendees->first; # First Attendee of a
specific Session.
$session_attendee->reviews; # return only review for that specific session
by this attendee.
For that to happen the $session_attendee needs to be specific to a given
session (Session id is stored with the $session_attendee instance).
If I have the row objects I could see doing something like:
package Session;
...
sub attendees {
my $self = shift;
my $rs = $self->session_attendees;
$rs->result_class( 'Session::Attendee' );
my @all = $rs->all;
for ( @all ) {
$_->session_id( $self->id );
}
return @all;
}
But, what I'm not clear on is how to be able to return a $rs directly so
that later $rs->all sets the Session on each Session::Attendee.
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]