Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Relational Query With Cdbcriteria And Cactivedataprovider

$
0
0
Alright forgive me as I am still new to Yii. I am trying to use the yii generated search in the model for the admin page, however since each element has a uniqe number of objects "has_many" relationship I want the admin page to only show the accounts associated with that user. I have been having the biggest PITA trying to figure this out for some reason but everything I have done has not worked.

Code I am refering to:
public function search()
{
     // Warning: Please modify the following code to remove attributes that
     // should not be searched.

     $criteria=new CDbCriteria;
     $criteria->compare('id',$this->id);
     $criteria->compare('AccountId',$this->AccountId);
     $criteria->compare('APIUsername',$this->APIUsername,true);
     $criteria->compare('request_limit',$this->request_limit);
     $criteria->compare('send_limit',$this->send_limit);
     $criteria->compare('uploads_limit',$this->uploads_limit);
     $criteria->compare('downloads_limit',$this->downloads_limit);

     return new CActiveDataProvider($this, array(
          'criteria'=>$criteria,
     ));



What I have tried to do:

 $criteria=new CDbCriteria;
 $criteria->with=array('apiAdministrator');
 $criteria->together = true;



I also tried setting the constructor:

return new CActiveDataProvider(APIUsers::model()->with('apiAdministrator'), array(
     'criteria'=>$criteria,
));



but that also did not work.

I have seen alot of people explaining this when the criteria is just an array and not actually set with the CDbCriteria so I am lost on how to do this, I also setup the relationship correctly in each relations function. I have no issue setting up the relations under most things but I want to use this GII generated code because it does everything I need it to do just with the only modification is it being relational.

Viewing all articles
Browse latest Browse all 18717


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>