Model Bug,relation With

[size="5"]controller code[/size]

public function actionIndex() {


	$posts = Post::model()->with(







//if the post do not has a comment,then the post can not show ,why? I just want the comment’s status is APPROVED.


			    			 'order'=>'comments.create_time  DESC'













[size="5"]view code[/size]

<?php foreach ($posts as $post) :?>

<?php // print_r($post);exit(); ?>

<?php echo $post->author->id.$post[‘author’][‘username’].“posts:”?><br/><br/>

title:<?php echo $post->title ;?><br/>

content :<?php echo $post->content ;?><br/><br/><br/>

评论:《<?php echo $post->commentCount ;?>》<br/><br/>

<?php foreach ($post->comments as $comment) :?>

content——》<?php echo $comment->content ;?><br/><br/>

status——》<?php echo $comment->status ;?><br/><br/>

<?php endforeach;?>

<?php endforeach;?>

[b]How to write the view to access the data? I use select but do not have a effect.

how to use the join,I use it but do not know how to show the numeric field.

who can help me write the demo code[/b]

[color="#556B2F"]/* Moved from "Bug Discussions" to "General Discussion for Yii 1.1.x" */[/color]

Hi new_yii, welcome to the forum.

As for the first question …

I think it’s because your are using the ‘condition’ option of the relation.

Try ‘on’ option instead, I hope it will do the job.



                'order'=>'comments.create_time DESC'