bgultekin / laravel4-datatables-package

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

SQLSTATE[HY000]: General error: 2031 for join query with 'where' #185

Open tony-was opened 9 years ago

tony-was commented 9 years ago

I ahve the following code snippet:

->leftJoin('blocked_users', function($join) use ($user_id, $id) { $join->on('users.id', '=', 'blocked_users.blocked_user_id') ->where('blocked_users.user_id', '=', $user_id); })

which throws the errors

SQLSTATE[HY000]: General error: 2031 (SQL: select count(*) as aggregate from...

not sure if anyone else is experiencing this.

CarterZhou commented 9 years ago

Try to use Eloquent in a simpler way?

->leftJoin('blocked_users', 'blocked_users.blocked_user_id','=',$user_id)

And I don't think it is a problem of bllim/laravel4-datatables-package. I would suggest you check Laravel documentation for more details.

tony-was commented 9 years ago

@CarterZhou If I run that it gives me an "Unknown Column" error as the last attribute needs to be a column name and not an actual value.

Though I think you are right I will need to re factor this to make it a little cleaner

brunoerg commented 6 years ago

Try it:

        'options'   => [
            \PDO::ATTR_EMULATE_PREPARES => true
        ] 

Put it on your database config if you are using mysql