MySQL returning nothing on a very simple query

I have a table called groups_pivot that has these columns:

id, pivot_id, group_id, model, creator_id, updater_id, created_at, updated_at

In it I store relationships between different models and groups:

select * from groups_pivot;

id  pivot_id    group_id    model           creator_id  updater_id  created_at       updated_at
1   1           1           App\Models\User 7           7           8/18/2019 22:09  8/18/2019 22:09
2   2           1           App\Models\User 1           1           8/18/2019 22:09  8/18/2019 22:09
3   3           2           App\Models\User 6           6           8/18/2019 22:09  8/18/2019 22:09
4   4           3           App\Models\User 2           2           8/18/2019 22:09  8/18/2019 22:09

But when I run this query in both Laravel and mySQLWorkbench I get null response:

select * from groups_pivot
where model = 'App\Models\User';

09:27:41    select * from groups_pivot where model = 'App\Models\User' LIMIT 0, 1000    0 row(s) returned   0.000 sec / 0.000 sec

What kind of magic is this? No errors, no response. I am sure I am having a stupid morning, but I cannot see why it is doing this. Thanks for any suggestions on where to look.

2 answers

  • answered 2019-08-18 23:33 Dime

    what about:

    select * from groups_pivot
    where model = 'App\\Models\\User';
    

    Backslash is often an escape character and thus requires to be escaped itself to be used.

  • answered 2019-08-18 23:36 ChrisFNZ

    Try using double quotes (") instead of an apostrophe (') to delimit your values because otherwise backslash is used to denote an escape character.