CDbCriteria relational merge can't get all data from joint table

Hi everyone,

This might be a stupid question but it’s late and I’m pulling my hair out. Hopefully one of you can enlighten me.

Lets say I have a User and Post system. I would like to get all the users that have at least one published post. Do to so I have made a new CDbCriteria accordingly.

I have however hit a wall as I would like my CActiveDataProvider to also return information regarding -all- posts linked to said users. As it stands, I’m only (and logically) getting my user information and information regarding the published posts.

Bellow is an idea of what the code looks like:

$criteria = new CDbCriteria(array('with' => array('posts'=> array('condition'=>'published=:published',

	    							  'params'=>array(':published'=> '1')



				  'together'	=> true,




return CActiveDataProvider('User',array('criteria'=>$preexisting_functional_criteria));

Thanks in advance.

You could write a getter-method in your User-model that returns information regardless of what the condition of your query is.


hth, yodel

Thanks for the help, but wouldn’t my getter have to query the DB? It feels like that would kind of defeat the purpose.

Yes, you would have to do that. Why would it defeat the purpose? Its purpose is to give you information from the DB. And that is what it does :-).

Maybe someone has a better idea, but that was the first thing I thought of. The second would be to use the afterFind method. But either way you have to do a query, because you’re limiting the result of the original query with the condition.