Category: Models & ORM

Q: How can I create subsquery of same query written in 2x

$conditionsSubQuery['Logs.title'] = $log_title;

$conditionsSubQuery['Logs.school_id'] = $school_id;

$db = $this->Log->getDataSource();

$subQuery = $db->buildStatement(

array(

'fields'     => array('Logs.grade_id'),

'table'      => $db->fullTableName($this->Log),

'alias'      => 'Logs',

'limit'      => null,

'offset'     => null,

'joins'      => array(),

'conditions' => $conditionsSubQuery,

'order'      => null,

'group'      => array('Logs.grade_id')

),

$this->Log

);

$subQuery = "Grade.id IN (" . $subQuery . ") ";

$dbgrade = $this->Grade->getDataSource();

$subQueryExpression = $dbgrade->expression($subQuery);

$conditions[] = $subQueryExpression;

$grade_lists = $this->Grade->find('list', array('conditions'=>$conditions,'recursive' => -1,'fields'=>array('Grade.id','Grade.name')));  

cakephp
0 Answers

No answers yet!

The community needs your help!

Post your Answer

Created: 18 Jul '18

Last Reply: None

Replies: 0

Views: 286

Votes: 0

Welcome to Aero Coding!

Aero Coding is a CakePHP-focused Q&A community for professional and enthusiast cake bakers. It's built and run by you as part of the community.


Join Now Tour

Download Cakephp

Start baking your own CakePHP application!


Cakephp All Versions