[Dbix-class] Dinamic join conditions

Tiziano Faion tiziano at graphistudio.com
Wed Sep 1 17:09:38 GMT 2010


Dear Mailing List,
i'm developing an utility to administrate some things in an intranet 
enviroinment.
I've got two tables one with 3 fields :
id,
seminar_group_id,
desc

and the other one that contains 3 fields also
id,
seminar_group_id
role_id

the second table contains the seminar group id that a role is able to see.
what i want to get is a complete list of the groups , and field that 
return true or false if a user can see the group.
i got this by executing this query
select
     a.id,
     group_name,
     role_id
from
     seminari_gruppi a
left join
     seminar_2_roles b
on
     ( a.id = b.seminar_group_id AND role_id = $role_id)

looking into google i've discovered that this can be done by using the 
from, and this is what i've done

my $allGroups_rs = $c->model('DbsMysql::Seminars::Gruppi')->search(undef,
     { from => \"
             (SELECT a.id , group_name, group_desc, testo , img , 
role_id FROM seminari_gruppi a
                 LEFT JOIN seminar_2_roles b
                     ON a.id = b.seminar_group_id
                     AND b.role_id = $id_role
             ) me"
         });

but... how can i access role_id ? as i can do a thing like this
push @{$json->{groups}} , {
                group_id  => $r->id,
             group_desc => $r->group_desc,
             group_name => $r->group_name,
             cansee => defined $r->{role_id} ? JSON::XS::true : 
JSON::XS::false
            };
Thanks guys!



More information about the DBIx-Class mailing list