假设我们有两个ORM模型:
class Model_User extends ORM
{
protected $_has_many = array(
'orders' => array(
'model' => 'Order',
'foreign_key' => 'order_id',
),
);
}
class Model_Order extends ORM
{
protected $_belongs_to = array(
'author' => array(
'model' => 'User',
'foreign_key' => 'author_id',
),
);
}
ORM::factory('User')->find_all(); //Displays a list of all users
您可以看到所有用户的列表,按订单数量排序?有可能吗?
答案 0 :(得分:0)
您可以使用order_by
ORM::factory('User')->order_by('order_id', 'desc')->find_all(); //Displays a list of all users