[Catalyst] ask for help on table with 2 similar columns

nhyda nhydanhyda at gmail.com
Thu Mar 18 16:23:14 GMT 2010


On Thu, Mar 18, 2010 at 11:39 AM, Rodrigo <rodrigolive at gmail.com> wrote:

>
> On Thu, Mar 18, 2010 at 2:57 PM, nhyda <nhydanhyda at gmail.com> wrote:
>
>> Thank you anyway.
>> I think I figure it out, it is just matter in what order you put all the=
 {
>> [ (.
>>
>
> Do you really need to create the has_many relationship and do a join? I
> would just search in table 2 like this:
>
> my $rs =3D $c->model('DB::Table2')->search({ -or =3D> [ left=3D>'B', righ=
t=3D>'B' ]
> });
>
> -rodrigo
>
> I think I do. Your solution return a resultset of table 2, but I need a
list of names from table 1.
here is what I end up doing.

my $rs =3D $c->model('DB::Table1')->search({'me.name' =3D> {'!=3D' =3D> 'B'=
},
               -or =3D> [{"table1_has_many_left_or_right".left =3D> 'B'},
                           {"table1_has_many_left_or_right".right =3D> 'B'}=
],
               {join =3D> 'table1_has_many_left_or_right', group_by =3D>['
me.name']})

and the has_many relation "table1_has_many_left_or_right" was defined as
("table1_has_many_left_or_right",
"DB:Table2",
[{left=3D>name},{right=3D>name}]);

it return a non-redundent list from table1 that neighboring B without B
itself.
I am sure there must be ways to do it better, cleaner and simpler, but at
least this work for me now.
any suggestion for improvement is well welcome.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100318/fab48=
4f5/attachment.htm


More information about the Catalyst mailing list