[Dbix-class] Finding in related rs ('s related rs ('s related ...
    fREW Schmidt 
    frioux at gmail.com
       
    Wed May 13 08:29:22 GMT 2009
    
    
  
Hello all!
This is mostly a reason that DBIC is excellent; consider showing it to
people who are die hard SQLers :-)
So here is my table structure:
User has many Roles (Role belongs to User)
Role has many Permissions (Permission belongs to)
Permissions has many Screens (Screens has many Permissions)
Screens belongs to Section (Section has many Screens)
So I thought I could do this:
   my @sections =3D $user->roles
      ->related_resultset('permissions')
      ->related_resultset('screens')
      ->related_resultset('section')
      ->all;
But related_resultset apparently doesn't work with many_to_many?
The following is *close* to what I wanted
   my @sections =3D $user->roles
      ->related_resultset('role_permissions')
      ->related_resultset('permission')
      ->related_resultset('permission_screens')
      ->related_resultset('screen')
      ->related_resultset('section')
      ->all;
But it turns out it returns a section per role, which often means
duplicates.
So I figured I could do a distinct, so I finally tried this:
   my @sections =3D $user->roles
      ->related_resultset('role_permissions')
      ->related_resultset('permission')
      ->related_resultset('permission_screens')
      ->related_resultset('screen')
      ->related_resultset('section')
      ->search(undef, { distinct =3D> 1 });
And it worked!  Hurray DBIC!
-- =
fREW Schmidt
http://blog.afoolishmanifesto.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20090513/840=
bbf75/attachment.htm
    
    
More information about the DBIx-Class
mailing list