使用Laravel查询构建器和LEFT JOIN删除行 [英] Delete rows with Laravel query builder and LEFT JOIN
本文介绍了使用Laravel查询构建器和LEFT JOIN删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在一个查询(带有左联接)中从多个表中删除行. 查询:
How to delete rows from multiple tables in one query (with left join). The query:
DELETE `deadline`, `job` FROM `deadline` LEFT JOIN `job` ....
所以,我这样尝试:
DB::table('deadline', 'job')
->leftJoin('job', 'deadline.id', '=', 'job.deadline_id')
->where('deadline.id', $id)
->delete();
Laravel似乎不支持从具有左联接的多个表中删除.
Seems that Laravel doesn't support delete from multiple tables with left join.
是否有受支持的方法或解决方法?
Is there a supported way or workaround?
推荐答案
看来我的方法行不通.所以,我是这样做的.
It seems that my way is not possible. So, I did it like this.
$q = 'DELETE deadline, job FROM deadline LEFT JOIN job ...where deadline.id = ?';
$status = \DB::delete($q, array($id));
文档: http://laravel.com/docs/database#running-queries
这篇关于使用Laravel查询构建器和LEFT JOIN删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文