Cakephp: contain with limit 1 not showing any associated items where there are more than 1 of them -
i have 2 models: surveyaccess , datapoint
they have habtm relationship.
if want list each surveyaccess , associated datapoints can this:
$t = $this->surveyaccess->find('all', array( 'contain' => array( 'datapoint' ), 'conditions' => $conds, )); //$conds limiting me specific set of surveyaccess items - not relevant here but want show first of each datapoint items (if any)
i tried this:
$t = $this->surveyaccess->find('all', array( 'contain' => array( 'datapoint' => array( 'limit' => 1 ) ), 'conditions' => $conds, )); i expect limit limit items returned 1 - instead returning empty array when there more 1 datapoint items so:
(int) 0 => array( 'surveyaccess' => array( 'id' => '63617', 'browser' => 'mozilla/5.0 (windows nt 6.3; wow64) applewebkit/537.36 (khtml, gecko) chrome/40.0.2214.115 safari/537.36', 'created' => '2015-02-28 01:55:28', 'read' => null ), 'datapoint' => array() ), ... (int) 2 => array( 'surveyaccess' => array( 'id' => '63615', 'browser' => 'mozilla/5.0 (windows nt 6.3; wow64) applewebkit/537.36 (khtml, gecko) chrome/40.0.2214.115 safari/537.36', 'created' => '2015-02-28 01:42:58', 'read' => null ), 'datapoint' => array( (int) 0 => array( 'id' => '258', 'datapointsurveyaccess' => array( 'id' => '258', 'surveyaccess_id' => '63615', 'datapoint_id' => '258' ) ) ) ), any thoughts on how this? can process array in php won't scale. can sub-query guess...
any appreciated. thanks
i think need find('first')
$t = $this->surveyaccess->find('first', array( 'contain' => array( 'datapoint' ), 'conditions' => $conds, )); updated
$t = $this->surveyaccess->find('all', array( 'limit' => 1, 'contain' => array( 'datapoint' ) ));
Comments
Post a Comment