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.