[Dbix-class] Retrieving join table info from many_to_many

Paul Makepeace paulm at paulm.com
Mon Feb 18 15:03:46 GMT 2008


Thanks Jess,

This is what I suspected I'd need to do -- thanks v much for the step-by-step!

(As it turns out it's shown up a bizarre error but I'll take that to a
new thread.)

P

On 2/18/08, Jess Robinson <castaway at desert-island.me.uk> wrote:
>
> Hi Paul,
>
> On Sun, 17 Feb 2008, Paul Makepeace wrote:
>
> > I have two tables of things, user and widget. I have a join table
> > user_widget and have set up the DBIC bits so I can say @widgets =
> > $user->widgets(). Now, for each of @widgets I actually want a piece of
> > info in user_widgets, color (i.e. each user can customize the
> > appearance of their widget).
>
> An m2m bridge is essentially a way to skip the link table and jump
> straight to the other side of it. If you want data from the link table,
> then use the link table rel?
>
> I assume your user has a has_many rel to user_widget, so replace :
>    my @widgets :Stashed = $user->widgets;
> with
>    my @widgets :Stashed = $user->link_widgets;
> And use $linkwidget.color, linkwidget.widget.name etc
>
> To prefetch:
>    my $widgets_rs :Stashed = $user->link_widgets->search({}, { prefetch =>
> 'widget' });
>
> > Is there any way to get that (ideally prefetched) color from the join
> > table, given a $bar? Or do I have to get a list of the join table
> > entries prefetching widget and then iterate over that?
> >
> > I'm aiming for, e.g.,
> >
> >  my @widgets :Stashed = $user->widgets;
> >
> >  [% FOREACH widget = widgets %]
> >   <td>[% widget.name %] has color [% widget.[magic here?].color %]</td>
> >  [% END %]
> >
>
> Jess
>
> _______________________________________________
> 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/dbix-class@lists.rawmode.org
>



More information about the DBIx-Class mailing list