Accessing related table via method of the table's name

2 messages Options
Embed this post
Permalink
Sixtease

Accessing related table via method of the table's name

Reply Threaded More More options
Print post
Permalink
Hello all,

I'm new to the list and fairly new to DBIx::Class as well.

I have built an application on Catalyst with PostgreSQL. I have a
table for contests and a table for rounds. Each round has its contest.
I've been using this way to access a round's contest:

$round = $c->model->resultset('Rounds')->find( $id );
$contest = $round->contest;

But then I had to upgrade from the DBIx::Class version I had from the
debian Catalyst package to latest and this no longer works. Now I have
to do like

$contest_id = $round->get_column('contest');
$contest = $c->model->resultset('Contests')->find( $contest_id );

which is clumsy at best. Is there a way to restore the original
functionality? I suppose it could have something to do with the fact
I'm using a dynamic DB model.

Thanks
~ Sixtease

_______________________________________________
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@...
Matt Whipple

Re: Accessing related table via method of the table's name

Reply Threaded More More options
Print post
Permalink
Sixtease wrote:

> Hello all,
>
> I'm new to the list and fairly new to DBIx::Class as well.
>
> I have built an application on Catalyst with PostgreSQL. I have a
> table for contests and a table for rounds. Each round has its contest.
> I've been using this way to access a round's contest:
>
> $round = $c->model->resultset('Rounds')->find( $id );
> $contest = $round->contest;
>  
I'm also new to both but I'll take a crack at this.  The find method
above returns a ResultSet while you're trying to operate on a Row.  You
probably want

$round = $c->model->resultset('Rounds')->find( $id )->single;


> But then I had to upgrade from the DBIx::Class version I had from the
> debian Catalyst package to latest and this no longer works. Now I have
> to do like
>
> $contest_id = $round->get_column('contest');
> $contest = $c->model->resultset('Contests')->find( $contest_id );
>
> which is clumsy at best. Is there a way to restore the original
> functionality? I suppose it could have something to do with the fact
> I'm using a dynamic DB model.
>
> Thanks
> ~ Sixtease
>
> _______________________________________________
> 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@...
>  


_______________________________________________
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@...