在模型中获取自定义顺序的正确方法是什么?是否有可能做到这一点?这是我目前的代码:
public function getBoardPosts()
{
return $this->hasMany(BoardPosts::className(), ['topic_id' => 'id'])->orderBy('order ASC');
}
答案 0 :(得分:1)
是的。以下是guide:
中的示例class Customer extends ActiveRecord
{
public function getBigOrders($threshold = 100)
{
return $this->hasMany(Order::className(), ['customer_id' => 'id'])
->where('subtotal > :threshold', [':threshold' => $threshold])
->orderBy('id');
}
}
请注意,您可能需要引用该字段(或者更好地使用非SQL字词命名您的列):
return $this->hasMany(BoardPosts::className(), ['topic_id' => 'id'])->orderBy('`order` ASC');