我有以下查询:订购关系列
$items = UserItems::with('item')
->where('user_id','=',$this->id)
->where('quantity','>',0)
->get();
我需要项目。形式来订购吧,所以我尝试:
$items = UserItems::with('item')
->where('user_id','=',$this->id)
->where('quantity','>',0)
->orderBy('item.type')
->get();
,但我得到Unknown column 'item.type' in 'order clause'
我我错过了?
是您的表名为项目或项目?我的猜测是你的关系被称为物品,但表格是物品,所以它应该是'orderBy('items.type')' – rypskar
我试过'列未找到:1054未知列'items.type'in'order clause' ' – TheUnreal
看看你的查询日志,你的主查询和关系是彼此分开的,它们不会交叉。你需要做一些类型的连接,以便能够通过另一个表进行排序,这很可能。 – lagbox