Housni Yakoob Sun May 20 16:55:17 -0400 2012

Subject: How do I generate this nested query?

I'm trying to figure out how to generate the following SQL:

1  SELECT * 
2    FROM  `resources` 
3   WHERE (`controller` =  'members' AND  `action` =  'login')
4      OR (`controller` =  'members' AND  `action` =  '*')
5      OR (`controller` =  '*'       AND  `action` =  '*')

I thought this might do it but this clearly yields a different query than the one I want.

1 $resource = Resource::find_by_controller_or_action(
2     array($request->controller, $request->action),
3     array($request->controller, '*'),
4     array('*', '*')
5 );

Help, please?


Megan McVey Wed May 30 15:47:46 -0400 2012

You could try something like...

1   $resource = Resource::find(array('conditions'=>array(
2     "(controller=? and action=?) or 
3      (controller=? and action='*') or 
4      (controller='*' and action='*')", 
5     $request->controller, $request->action, $request->controller
6   )));

it's a little less "elegant" than the magic methods but it should generate what you want.

(1-1/1)