bgultekin / laravel4-datatables-package

Server-side handler of DataTables Jquery Plugin for Laravel 4
267 stars 108 forks source link

works well and throw exception when search #84

Closed OmarMakled closed 10 years ago

OmarMakled commented 10 years ago

that code works well but when search throw exception: "Cardinality violation: 1241 Operand should contain 1 column(s) .. "

          $foo = '';
    foreach (Store::getList() as $key => $value) {
        $foo .= "(SELECT
                warehouses.quantity
            FROM
                warehouses
            INNER JOIN items ON warehouses.item_id = items.id
            INNER JOIN stores ON warehouses.store_id = stores.id
            where 
                warehouses.item_id = items.id
            AND
                stores.id = $key) ,";
    }
    // remove last , to correct syntax
    $foo = substr($foo, 0, -1);

    $boo = DB::table("warehouses")
        ->join('items','warehouses.item_id','=','items.id')
        ->select(
            'items.id as itemId',
            'items.item_code as itemCode',
            'items.name as itemName',
            DB::raw($foo)
        )
        ->distinct();

    return Datatables::of($boo)

    ->remove_column('itemId')

    ->make();

I think here is the issue Bllim\Datatables\Datatables.php

private function count($count = 'count_all')
{
    //Get columns to temp var.
    $query = $this->query_type == 'eloquent' ? $this->query->getQuery() : $this->query;

    //Count the number of rows in the select
    $this->$count = DB::table(DB::raw('('.$query->toSql().') AS count_row_table'))
    ->setBindings($query->getBindings())->count();
}
ktunkiewicz commented 10 years ago

Duplicate of #88 , will be fixed soon.