2017-06-10 10 views
0

yatara laravelデータ型を使用して、データテーブルにデータを取り込みます。複合ジョインが動作していないLaravelデータ型

私は様々含め、非常に複雑なクエリが参加しています

$activityList = DB::table('activities') 
    ->select('u2.id as manager_id','u2.name as manager_name','u.id as user_id','u.name as user_name','p.id as project_id','p.project_name as project_name','p.customer_name as customer_name','activities.year as year') 

->leftjoin('projects as p', 'p.id', '=', 'activities.project_id') 
->leftjoin('users as u', 'u.id', '=', 'activities.user_id') 
->leftjoin('users_users as uu', 'u.id', '=', 'uu.user_id') 
->leftjoin('users AS u2', 'u2.id', '=', 'uu.manager_id'); 

    $data = Datatables::of($activityList)->make(true); 
    return $data; 

を、私は私のジャバスクリプトを持っている:

activitiesTable = $('#activitiesTable').DataTable({ 
       scrollX: true, 
       serverSide: true, 
       processing: true, 
       ajax: { 
         url: "{!! route('listOfActivitiesPerUserAjax') !!}", 
         type: "POST", 
         data: ajaxData, 
         dataType: "JSON" 
        }, 
       columns: [ 
        { name: 'u2.id', data: 'manager_id' , searchable: false , visible: false}, 
        { name: 'u2.name', data: 'manager_name', width: '150px' }, 
        { name: 'u.id', data: 'user_id' , searchable: false , visible: false}, 
        { name: 'u.name', data: 'user_name' , width: '150px'}, 
        { name: 'p.customer_name', data: 'customer_name' , width: '200px'}, 
        { name: 'p.id', data: 'project_id' , searchable: false , visible: false}, 
        { name: 'p.project_name', data: 'project_name', width: '200px'}, 
        { name: 'activities.year', data: 'year' , searchable: false , visible: false}, 
        { 
         name: 'actions', 
         data: null, 
         sortable: false, 
         searchable: false, 
         render: function (data) { 
          var actions = ''; 
          return actions; 
         } 
        } 
        ], 
       order: [[2, 'asc']], 

私はそれはサーバーサイドで動作させることはできません。

私がサーバサイドを使用しないと、すべてうまくいきますが、サーバサイドを設定するとすぐに、すべてのデータが取得され、レコードの数が制限され、検索はソートがもう機能しなくなります。

{"draw":0,"recordsTotal":1,"recordsFiltered":1,"data":[{"manager_id":13,"manager_name":"test manager","user_id":14,"user_name":"testuser","project_id":48,"project_name":"Test project","customer_name":"test customer","year":2017,"jan_com":10,"jan_otl":"0","feb_com":32,"feb_otl":"0","mar_com":0,"mar_otl":"0","apr_com":0,"apr_otl":"0","may_com":0,"may_otl":"0","jun_com":0,"jun_otl":"0","jul_com":0,"jul_otl":"0","aug_com":0,"aug_otl":"0","sep_com":0,"sep_otl":"0","oct_com":0,"oct_otl":"0","nov_com":0,"nov_otl":"0","dec_com":0,"dec_otl":"0"}],"queries":[{"query":"select count(*) as aggregate from (select `u2`.`id` as `manager_id`, `u2`.`name` as `manager_name`, `u`.`id` as `user_id`, `u`.`name` as `user_name`, `p`.`id` as `project_id`, `p`.`project_name` as `project_name`, `p`.`customer_name` as `customer_name`, `activities`.`year` as `year`, if(sum(if(activities.from_otl=1 and month=1,task_hour,0))>0,sum(if(activities.from_otl=1 and month=1,task_hour,0)),sum(if(activities.from_otl=0 and month=1,task_hour,0))) jan_com, if(sum(if(activities.from_otl=1 and month=1,task_hour,0))>0,sum(if(activities.from_otl=1 and month=1,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=1,activities.from_otl,0))) jan_otl, if(sum(if(activities.from_otl=1 and month=2,task_hour,0))>0,sum(if(activities.from_otl=1 and month=2,task_hour,0)),sum(if(activities.from_otl=0 and month=2,task_hour,0))) feb_com, if(sum(if(activities.from_otl=1 and month=2,task_hour,0))>0,sum(if(activities.from_otl=1 and month=2,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=2,activities.from_otl,0))) feb_otl, if(sum(if(activities.from_otl=1 and month=3,task_hour,0))>0,sum(if(activities.from_otl=1 and month=3,task_hour,0)),sum(if(activities.from_otl=0 and month=3,task_hour,0))) mar_com, if(sum(if(activities.from_otl=1 and month=3,task_hour,0))>0,sum(if(activities.from_otl=1 and month=3,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=3,activities.from_otl,0))) mar_otl, if(sum(if(activities.from_otl=1 and month=4,task_hour,0))>0,sum(if(activities.from_otl=1 and month=4,task_hour,0)),sum(if(activities.from_otl=0 and month=4,task_hour,0))) apr_com, if(sum(if(activities.from_otl=1 and month=4,task_hour,0))>0,sum(if(activities.from_otl=1 and month=4,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=4,activities.from_otl,0))) apr_otl, if(sum(if(activities.from_otl=1 and month=5,task_hour,0))>0,sum(if(activities.from_otl=1 and month=5,task_hour,0)),sum(if(activities.from_otl=0 and month=5,task_hour,0))) may_com, if(sum(if(activities.from_otl=1 and month=5,task_hour,0))>0,sum(if(activities.from_otl=1 and month=5,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=5,activities.from_otl,0))) may_otl, if(sum(if(activities.from_otl=1 and month=6,task_hour,0))>0,sum(if(activities.from_otl=1 and month=6,task_hour,0)),sum(if(activities.from_otl=0 and month=6,task_hour,0))) jun_com, if(sum(if(activities.from_otl=1 and month=6,task_hour,0))>0,sum(if(activities.from_otl=1 and month=6,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=6,activities.from_otl,0))) jun_otl, if(sum(if(activities.from_otl=1 and month=7,task_hour,0))>0,sum(if(activities.from_otl=1 and month=7,task_hour,0)),sum(if(activities.from_otl=0 and month=7,task_hour,0))) jul_com, if(sum(if(activities.from_otl=1 and month=7,task_hour,0))>0,sum(if(activities.from_otl=1 and month=7,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=7,activities.from_otl,0))) jul_otl, if(sum(if(activities.from_otl=1 and month=8,task_hour,0))>0,sum(if(activities.from_otl=1 and month=8,task_hour,0)),sum(if(activities.from_otl=0 and month=8,task_hour,0))) aug_com, if(sum(if(activities.from_otl=1 and month=8,task_hour,0))>0,sum(if(activities.from_otl=1 and month=8,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=8,activities.from_otl,0))) aug_otl, if(sum(if(activities.from_otl=1 and month=9,task_hour,0))>0,sum(if(activities.from_otl=1 and month=9,task_hour,0)),sum(if(activities.from_otl=0 and month=9,task_hour,0))) sep_com, if(sum(if(activities.from_otl=1 and month=9,task_hour,0))>0,sum(if(activities.from_otl=1 and month=9,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=9,activities.from_otl,0))) sep_otl, if(sum(if(activities.from_otl=1 and month=10,task_hour,0))>0,sum(if(activities.from_otl=1 and month=10,task_hour,0)),sum(if(activities.from_otl=0 and month=10,task_hour,0))) oct_com, if(sum(if(activities.from_otl=1 and month=10,task_hour,0))>0,sum(if(activities.from_otl=1 and month=10,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=10,activities.from_otl,0))) oct_otl, if(sum(if(activities.from_otl=1 and month=11,task_hour,0))>0,sum(if(activities.from_otl=1 and month=11,task_hour,0)),sum(if(activities.from_otl=0 and month=11,task_hour,0))) nov_com, if(sum(if(activities.from_otl=1 and month=11,task_hour,0))>0,sum(if(activities.from_otl=1 and month=11,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=11,activities.from_otl,0))) nov_otl, if(sum(if(activities.from_otl=1 and month=12,task_hour,0))>0,sum(if(activities.from_otl=1 and month=12,task_hour,0)),sum(if(activities.from_otl=0 and month=12,task_hour,0))) dec_com, if(sum(if(activities.from_otl=1 and month=12,task_hour,0))>0,sum(if(activities.from_otl=1 and month=12,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=12,activities.from_otl,0))) dec_otl from `activities` left join `projects` as `p` on `p`.`id` = `activities`.`project_id` left join `users` as `u` on `u`.`id` = `activities`.`user_id` left join `users_users` as `uu` on `u`.`id` = `uu`.`user_id` left join `users` as `u2` on `u2`.`id` = `uu`.`manager_id` where (`year` = ?) and (`u2`.`id` = ?) group by `manager_id`, `manager_name`, `user_id`, `user_name`, `project_id`, `project_name`, `year`) count_row_table","bindings":["2017","13"],"time":1.2},{"query":"select `u2`.`id` as `manager_id`, `u2`.`name` as `manager_name`, `u`.`id` as `user_id`, `u`.`name` as `user_name`, `p`.`id` as `project_id`, `p`.`project_name` as `project_name`, `p`.`customer_name` as `customer_name`, `activities`.`year` as `year`, if(sum(if(activities.from_otl=1 and month=1,task_hour,0))>0,sum(if(activities.from_otl=1 and month=1,task_hour,0)),sum(if(activities.from_otl=0 and month=1,task_hour,0))) jan_com, if(sum(if(activities.from_otl=1 and month=1,task_hour,0))>0,sum(if(activities.from_otl=1 and month=1,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=1,activities.from_otl,0))) jan_otl, if(sum(if(activities.from_otl=1 and month=2,task_hour,0))>0,sum(if(activities.from_otl=1 and month=2,task_hour,0)),sum(if(activities.from_otl=0 and month=2,task_hour,0))) feb_com, if(sum(if(activities.from_otl=1 and month=2,task_hour,0))>0,sum(if(activities.from_otl=1 and month=2,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=2,activities.from_otl,0))) feb_otl, if(sum(if(activities.from_otl=1 and month=3,task_hour,0))>0,sum(if(activities.from_otl=1 and month=3,task_hour,0)),sum(if(activities.from_otl=0 and month=3,task_hour,0))) mar_com, if(sum(if(activities.from_otl=1 and month=3,task_hour,0))>0,sum(if(activities.from_otl=1 and month=3,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=3,activities.from_otl,0))) mar_otl, if(sum(if(activities.from_otl=1 and month=4,task_hour,0))>0,sum(if(activities.from_otl=1 and month=4,task_hour,0)),sum(if(activities.from_otl=0 and month=4,task_hour,0))) apr_com, if(sum(if(activities.from_otl=1 and month=4,task_hour,0))>0,sum(if(activities.from_otl=1 and month=4,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=4,activities.from_otl,0))) apr_otl, if(sum(if(activities.from_otl=1 and month=5,task_hour,0))>0,sum(if(activities.from_otl=1 and month=5,task_hour,0)),sum(if(activities.from_otl=0 and month=5,task_hour,0))) may_com, if(sum(if(activities.from_otl=1 and month=5,task_hour,0))>0,sum(if(activities.from_otl=1 and month=5,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=5,activities.from_otl,0))) may_otl, if(sum(if(activities.from_otl=1 and month=6,task_hour,0))>0,sum(if(activities.from_otl=1 and month=6,task_hour,0)),sum(if(activities.from_otl=0 and month=6,task_hour,0))) jun_com, if(sum(if(activities.from_otl=1 and month=6,task_hour,0))>0,sum(if(activities.from_otl=1 and month=6,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=6,activities.from_otl,0))) jun_otl, if(sum(if(activities.from_otl=1 and month=7,task_hour,0))>0,sum(if(activities.from_otl=1 and month=7,task_hour,0)),sum(if(activities.from_otl=0 and month=7,task_hour,0))) jul_com, if(sum(if(activities.from_otl=1 and month=7,task_hour,0))>0,sum(if(activities.from_otl=1 and month=7,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=7,activities.from_otl,0))) jul_otl, if(sum(if(activities.from_otl=1 and month=8,task_hour,0))>0,sum(if(activities.from_otl=1 and month=8,task_hour,0)),sum(if(activities.from_otl=0 and month=8,task_hour,0))) aug_com, if(sum(if(activities.from_otl=1 and month=8,task_hour,0))>0,sum(if(activities.from_otl=1 and month=8,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=8,activities.from_otl,0))) aug_otl, if(sum(if(activities.from_otl=1 and month=9,task_hour,0))>0,sum(if(activities.from_otl=1 and month=9,task_hour,0)),sum(if(activities.from_otl=0 and month=9,task_hour,0))) sep_com, if(sum(if(activities.from_otl=1 and month=9,task_hour,0))>0,sum(if(activities.from_otl=1 and month=9,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=9,activities.from_otl,0))) sep_otl, if(sum(if(activities.from_otl=1 and month=10,task_hour,0))>0,sum(if(activities.from_otl=1 and month=10,task_hour,0)),sum(if(activities.from_otl=0 and month=10,task_hour,0))) oct_com, if(sum(if(activities.from_otl=1 and month=10,task_hour,0))>0,sum(if(activities.from_otl=1 and month=10,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=10,activities.from_otl,0))) oct_otl, if(sum(if(activities.from_otl=1 and month=11,task_hour,0))>0,sum(if(activities.from_otl=1 and month=11,task_hour,0)),sum(if(activities.from_otl=0 and month=11,task_hour,0))) nov_com, if(sum(if(activities.from_otl=1 and month=11,task_hour,0))>0,sum(if(activities.from_otl=1 and month=11,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=11,activities.from_otl,0))) nov_otl, if(sum(if(activities.from_otl=1 and month=12,task_hour,0))>0,sum(if(activities.from_otl=1 and month=12,task_hour,0)),sum(if(activities.from_otl=0 and month=12,task_hour,0))) dec_com, if(sum(if(activities.from_otl=1 and month=12,task_hour,0))>0,sum(if(activities.from_otl=1 and month=12,activities.from_otl,0)),sum(if(activities.from_otl=0 and month=12,activities.from_otl,0))) dec_otl from `activities` left join `projects` as `p` on `p`.`id` = `activities`.`project_id` left join `users` as `u` on `u`.`id` = `activities`.`user_id` left join `users_users` as `uu` on `u`.`id` = `uu`.`user_id` left join `users` as `u2` on `u2`.`id` = `uu`.`manager_id` where (`year` = ?) and (`u2`.`id` = ?) group by `manager_id`, `manager_name`, `user_id`, `user_name`, `project_id`, `project_name`, `year`","bindings":["2017","13"],"time":0.92}],"input":{"year":["2017"],"manager":["13"]}} 

最後に、limitパラメータまたはoffsetパラメータは追加されません。

+0

あなたのスクリプトからのJSONレスポンスを投稿してくださいことはできますか? –

答えて

0

datatablesデモアプリケーションでは、select文の前に結合が行われます。私は流暢なクエリビルダでdatatablesを使用したことがないので、それが問題を引き起こしているかどうかは確かではありませんが、調べる価値があるかもしれません。ここでのコード例を参照してください。

https://datatables.yajrabox.com/fluent/joins

基本Serivceの実装:

https://datatables.yajrabox.com/services/basic

+0

何も変更されません。流暢なクエリビルダを使用しない場合は、代わりに何を使用しますか?そしてそれはどうやって動いていますか? – Richard

+0

私はEloquentを私のニーズの大部分と他の時代のコレクションに使用しています。また、パッケージをサービスとして設定して、すべてのクエリを自動的に処理するようにしました。 – btl

関連する問題