0

I have these tables and the relationships between them:

  • 1 project hasmany configurationcontext 1 issuetype hasmany
  • optionconfiguration hasmany configurationcontext hasmany
  • optionconfiguration (does not exist intermediate table)

My goal is to get information like this query.

SELECT IT.id, IT.pname
FROM configurationcontext               CC
LEFT OUTER JOIN optionconfiguration     OC ON OC.fieldconfig = CC.fieldconfigscheme
LEFT OUTER JOIN issuetype               IT ON IT.id = OC.optionid
WHERE CC.project = 10000

my doubts: - which the controller to use to create a function that return me this information? - How do I get this information?

thanks :)

4

1 回答 1

0

Assuming I have your model names correct, this should do the trick:

$this->ConfigurationContext->find('all', array(
    'joins' => array(
        array(
            'table' => 'optionconfiguration',
            'alias' => 'OptionConfiguration',
            'type' => 'LEFT OUTER JOIN',
            'conditions' => array(
                'OptionConfiguration.fieldconfig = ConfigurationContext.fieldconfigscheme'
            )
        ),
        array(
            'table' => 'issuetype',
            'alias' => 'IssueType',
            'type' => 'LEFT OUTER JOIN',
            'conditions' => array(
                'IssueType.id = OptionConfiguration.optionid'
            )
        )
    ),
    'conditions' => array(
        'ConfigurationContext.project' => 10000
    ),
    'fields' => array(
        'IssueType.id',
        'IssueType.pname'
    )
));

I haven't tried type "LEFT OUTER JOIN" but I don't see why it wouldn't work, maybe look into using containable to avoid using joins if you can.

于 2013-05-15T19:44:43.027 回答