CActiveDataProvider Join - Unexpected Results

Hi,

I am trying to find all Posts that have pending (Status = 1) Bids. I have a HAS_MANY relationship from Post -> Bid and BELONGS_TO relationship from Bid -> Post.

The conditions are fairly straightforward. The Post status and Bid status must be Open and the Author of the Post should be the logged in user.

Unexpected results: I am using a CListView to display the results. It appears as if the $model object is "merged" with other records. Ex. The Title is correct but the author & bidCount properties are wrong. To me, this indicates something wrong with my SQL.




$dataProvider=new CActiveDataProvider('Post', 

	array(

		'criteria' => array(

                 'join' => 'INNER JOIN {{bid}} ON t.id = {{bid}}.post_id',

			'condition'=>'{{bid}}.status=:bidStatus AND t.status=:postStatus AND t.created_by=:author',

			'params'=>array(

				':postStatus'=>Post::STATUS_OPEN, 

				':bidStatus'=>Bid::STATUS_OPEN,

				':author'=>Yii::app()->user->id,

                 ),

			'order'=>'t.id DESC',

          	'pagination'=>array(

            	'pageSize'=>Yii::app()->params['postsPerPage']

                 ),

	  	)

	)

);



Any ideas? Please let me know if you need additional info. I have attached a screenshot showing the fudged data and SQL profile output.

Cheers.

I thought this was resolved but I wrong. Does’t seem to be using my With clause at all. No matter what I change the Bid status to, it still return all Open Posts.

To summarize:

[list=1]

[*]I am trying to find all Posts with at least 1 Open Bid.

[*]Post HAS_MANY Bids

[*]Bid BELONGS_TO Post

[/list]




$dataProvider=new CActiveDataProvider('Post', 

			array(

				'criteria' => array(

					'condition'=>'t.status=:postStatus AND t.created_by=:author',

					'params'=>array(

						':postStatus'=>$postStatus, 

						':author'=>Yii::app()->user->id,),

					'with'=>array(

						'bids'=>array(

	                 		'condition'=>'bids.status=:bidStatus',

		                 	'params'=>array(

		                 		':bidStatus'=>$bidStatus,

							),

						),

					),

					'order'=>'t.created_on DESC',

		          	'pagination'=>array(

		            	'pageSize'=>Yii::app()->params['postsPerPage']),

			  	)

			)

		);



Cheers