Fixes table alias bug in complex queries for Laravel

This commit is contained in:
snipe 2017-10-18 01:21:08 -07:00
parent 6bd49bfb72
commit ea63ced2bd

View file

@ -146,39 +146,40 @@ class AssetsController extends Controller
$assets->withTrashed()->Deleted(); $assets->withTrashed()->Deleted();
break; break;
case 'Pending': case 'Pending':
$assets->join('status_labels',function ($join) { $assets->join('status_labels AS status_alias',function ($join) {
$join->on('status_labels.id', "=", "assets.status_id") $join->on('status_alias.id', "=", "assets.status_id")
->where('status_labels.deployable','=',0) ->where('status_alias.deployable','=',0)
->where('status_labels.pending','=',1) ->where('status_alias.pending','=',1)
->where('status_labels.archived', '=', 0); ->where('status_alias.archived', '=', 0);
}); });
break; break;
case 'RTD': case 'RTD':
$assets->join('status_labels',function ($join) { $assets->whereNull('assets.assigned_to')
$join->on('status_labels.id', "=", "assets.status_id") ->join('status_labels AS status_alias',function ($join) {
->where('status_labels.deployable','=',1) $join->on('status_alias.id', "=", "assets.status_id")
->where('status_labels.pending','=',0) ->where('status_alias.deployable','=',1)
->where('status_labels.archived', '=', 0); ->where('status_alias.pending','=',0)
->where('status_alias.archived', '=', 0);
}); });
break; break;
case 'Undeployable': case 'Undeployable':
$assets->Undeployable(); $assets->Undeployable();
break; break;
case 'Archived': case 'Archived':
$assets->join('status_labels',function ($join) { $assets->join('status_labels AS status_alias',function ($join) {
$join->on('status_labels.id', "=", "assets.status_id") $join->on('status_alias.id', "=", "assets.status_id")
->where('status_labels.deployable','=',0) ->where('status_alias.deployable','=',0)
->where('status_labels.pending','=',0) ->where('status_alias.pending','=',0)
->where('status_labels.archived', '=', 1); ->where('status_alias.archived', '=', 1);
}); });
break; break;
case 'Requestable': case 'Requestable':
$assets->where('assets.requestable', '=', 1) $assets->where('assets.requestable', '=', 1)
->join('status_labels',function ($join) { ->join('status_labels AS status_alias',function ($join) {
$join->on('status_labels.id', "=", "assets.status_id") $join->on('status_alias.id', "=", "assets.status_id")
->where('status_labels.deployable','=',1) ->where('status_alias.deployable','=',1)
->where('status_labels.pending','=',0) ->where('status_alias.pending','=',0)
->where('status_labels.archived', '=', 0); ->where('status_alias.archived', '=', 0);
}); });
break; break;
@ -188,9 +189,9 @@ class AssetsController extends Controller
break; break;
default: default:
// terrible workaround for complex-query Laravel bug in fulltext // terrible workaround for complex-query Laravel bug in fulltext
$assets->join('status_labels',function ($join) { $assets->join('status_labels AS status_alias',function ($join) {
$join->on('status_labels.id', "=", "assets.status_id") $join->on('status_alias.id', "=", "assets.status_id")
->where('status_labels.archived', '=', 0); ->where('status_alias.archived', '=', 0);
}); });
} }