Thanks AD7six and Christoph,

got everything working with minimum SQL and in a clean way...

For others reference.....this was my solution

$criteria =  array('user_id' => "{$userid}"); // basicaly get id of the
user
$songlist = $this->SongsUser->findAll($criteria, array('song_id'),
null, null, -1);  // find all the songs that in the library of the user
and set recursive to -1

$mySongList = array();
foreach($songlist as $value){
      $mySongList[] = $value['SongsUser']['song_id'];  // this is data
massaging for the next step
}

// now based on the list of the songs get unique list of singers
$this->Singer->SingersSong->unbindModel(array('belongsTo'=>array('Song')));
// I don't want to retrieve details about songs and hence unbinding
songs model
$singerList =
$this->Singer->SingersSong->findAll(array("SingersSong.song_id" =>
$mySongList), array('DISTINCT Singer.id', 'Singer.name'), null, null,
null, null, 1);

// since i also wanted count...I need to run a loop and use findCount
...I am cleaning some data
$singers = array();
foreach($singerList as $value){
           $temp['id'] = $value['Singer']['id'];
          $temp['name'] = $value['Singer']['fname'];
          $temp['count'] =
$this->SingersSong->findCount(array('SingersSong.song_id' =>
$mySongList,

'SingersSong.singer_id'  => $value['Singer']['id']));
         $singers[] = $temp;
}
print_r($singers);


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~----------~----~----~----~------~----~------~--~---

Reply via email to