Oh, i’m sorry, i think there was some issue with using the ‘together’ option in ‘with’ in a criteria. It behaves different than querying …->with()->together()->…
So maybe better check the workaround in the link provided by Horacio Segura above.
Thank you all for the very fast help! I solved the "problem" with help of the provided links like this:
class User extends CActiveRecord {
.....
public function search() {
$criteria->with = array('groups'=>array('select'=>'groups.name'));
$criteria->addSearchCondition('groups.name','1a');
return new ManyManyCActiveDataProvider('User', array(
'criteria'=>$criteria,
'together'=>true,
'sort'=>array(
'defaultOrder'=>'username DESC',
),
));
...
My data provider:
class ManyManyCActiveDataProvider extends CActiveDataProvider
{
public $together = false;
/**
* Fetches the data from the persistent data storage.
* @return array list of data items
*/
protected function fetchData()
{
$criteria=clone $this->getCriteria();
if(($pagination=$this->getPagination())!==false)
{
$pagination->setItemCount($this->getTotalItemCount());
$pagination->applyLimit($criteria);
}
if(($sort=$this->getSort())!==false)
$sort->applyOrder($criteria);
if ($this->together)
{
return CActiveRecord::model(
$this->modelClass)->with(
$criteria->with)->together()->findAll($criteria);
}
else
{
return CActiveRecord::model(
$this->modelClass)->findAll($criteria);
}
}
}
Thats working for me. Still wondering what would be the intended way to do this.