[Dbix-class] $c->stash for complex/cascaded relationship bridges

Alexander Hartmaier alexander.hartmaier at t-systems.at
Mon Jan 23 17:42:45 GMT 2012


You meant related_resultset, there is no such thing as a recordset in DBIC.
Also why don't you use find if you want to fetch a single result object fro=
m the database?
You can use HRI with find too if that was the reason.

Am 2012-01-23 16:20, schrieb will trillich:
Whoops--

On Mon, Jan 23, 2012 at 9:19 AM, will trillich <will.trillich at serensoft.com=
<mailto:will.trillich at serensoft.com>> wrote:
Can you use related_resultset or search_related?

# See https://metacpan.org/module/DBIx::Class::ResultSet#related_resultset
$table4_rs =3D $table1_rs->search_related_rs('table2')->search_related_rs('=
table4');

I meant

$table4_rs =3D $table1_rs->related_recordset('table2')->related_recordset('=
table4');

:)

# See https://metacpan.org/module/DBIx::Class::Manual::Features#search_rela=
ted
$table4_rs =3D $table1_rs
    ->search_related_rs( table2 =3D> { fld =3D> 'blah' } )
    ->search_related_rs('table4' =3D> { xyz =3D> 'pdq' } );

You can also inject utility methods into your schema definitions to return =
various related recordsets as well.



On Mon, Jan 23, 2012 at 8:55 AM, Roland Philibert <rphilibert at aptina.com<ma=
ilto:rphilibert at aptina.com>> wrote:
I manage to go through the database from a given primary key by doing in
the controller:

...
   my $pk =3D '1';
   my $t1 =3D $c->model('DB')->resultset('Table1')->search({ table1id =3D>
$pk,},
                                                         {result_class
=3D> 'DBIx::Class::ResultClass::HashRefInflator',});

   my $rs_t2 =3D $c->model('DB')->resultset('Table2')->search({
'table3s.ftable1id' =3D> $pk ,},
                                                         {join =3D> {
'table3s'},

result_class =3D> 'DBIx::Class::ResultClass::HashRefInflator',});

   while ( my $subrs =3D $rs_t2->next ) {
      $subrs =3D $c->model('DB')->resultset('Table2')->search(   {
table2id =3D> $subrs->{table2id},  },   { } );
      push @t2 , $subrs;
   }
   $c->stash(
               t1 =3D> [ $t1 ] ,
               rst2 =3D> \@t2
            );
   $c->detach($c->view("HTML"));
}



..so that's a lof of searches,
The first one is to get the info related to table1.
The second one is to get all related table2 items related to pk of
table1.
The loop create a search for each items of the second search to get
items from table4.

....keep thinking that there must be a simpler way?
Any help greatly appreciated.

Thanks


















Aptina (UK) Limited, Century Court, Millennium Way, Bracknell, Berkshire, R=
G12 2XT. Registered in England No. 06570543.

This e-mail and any attachments contain confidential information and are so=
lely for the review and use of the intended recipient. If you have received=
 this e-mail in error, please notify the sender and destroy this e-mail and=
 any copies.


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class<http://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.scsys.co=
.uk



--
"We act as though comfort and luxury were the chief requirements of life, w=
hen all that we need to make us happy is something to be enthusiastic about=
." -- Albert Einstein




--
"We act as though comfort and luxury were the chief requirements of life, w=
hen all that we need to make us happy is something to be enthusiastic about=
." -- Albert Einstein




_______________________________________________
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.scsys.co=
.uk


*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*=
"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*=
"*
Notice: This e-mail contains information that is confidential and may be pr=
ivileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*=
"*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20120123/c08=
605e1/attachment-0001.htm


More information about the DBIx-Class mailing list