[Dbix-class] Handling Multiple join

Wolfgang Kinkeldei wolfgang at kinkeldei.de
Fri Dec 31 08:39:42 GMT 2010


Hi,

Am 30.12.2010 um 06:45 schrieb linuxsupport:

> Hi all,
> 
> If I join multiple tables and one of the table contains more than 1 row and all records appear in more than 1 row.
> 
> for example, table1 has id and create_date, table2 has author_name, table3 has gorup_name and these can return only one row for a given id, but table4 can have more than 1 record for given id ( id from table1 refers in every tables), so it return like
> 
> id     |   create_date   | author_name    | group_name | comment_id
> 1      |    2010-12-26   | name1             | group1          | 1
> 1      |    2010-12-26   | name1             | group1          | 2 -- more than 1 comment_id for id -> 1
> 
> Is there a way to tell search query to store the results of column commnet_id into another list or array? otherwise how to handle it?

You could try to use DBIx::Class::ResultClass::HashRefInflator. If you prefetch your other tables, an array-ref for "has-many" related tables will be generated. However, the downside is that your retrieved "records" are not Objects anymore. Updates or Deletes will not work. You have been warned :-)


Best,

Wolfgang Kinkeldei

-- 

' /\_/\ ' .print[split??,"".(($/=q|Cms)+-03467:;<=|)=~tr!C-z -B! -z!)x
'( o.o )' .$/]->[hex]foreach split qr<>,qq+1ecd039ad65b025b8063475b+||
' > ^ < ' .q<!-- Wolfgang Kinkeldei - mailto:wolfgang at kinkeldei.de -->





More information about the DBIx-Class mailing list