我有这段代码,例如:
$rows = Category::find()
->select('id_category, SUM(p.comments * 10) AS num')
->leftJoin('post p', 'p.id = post_id')
->groupBy('id_category')
->one();
存在:$rows->id_category
但这不存在:$rows->num
答案 0 :(得分:1)
您需要一个名为' num'的字段。在您的类别模型中,否则您无法访问此值。以这种方式添加public var $ num
class Category extends \yii\db\ActiveRecord
{
public $num;
/**
* @inheritdoc
*/
public static function tableName()