Vinelab / NeoEloquent

The Neo4j OGM for Laravel
MIT License
633 stars 199 forks source link

Support whereRaw? #204

Closed thanosalexander closed 7 years ago

thanosalexander commented 7 years ago

I tried to use whereRaw inside a query but with no success!

ErrorException in Builder.php line 778: Undefined offset: 0

Is there support for this?

gemini-git commented 7 years ago

How do you call whereRaw? As I see NeoEloquent does not override the method.

thanosalexander commented 7 years ago

I know! Thats why i open the ticket, if it will be added!

gemini-git commented 7 years ago

I actually meant that it is not absolutely necessary that NeoEloquent overrides the method. It seems that the second param bindings produces the error. That's why I wanted to see how you call whereRaw.

thanosalexander commented 7 years ago

eg i want users that doesnt have articles User::whereRaw(' NOT (article)->[:HAS_ARTICLE]->()' )->get() i tried with laravel's built in doesntHave and has but with no success If i could run this command inside whereRaw,it will be ok

gemini-git commented 7 years ago

After looking at line 778 in Builder.php, I think it's a bug. whereRaw doesn't need bindings but the method addBinding expects that the binding-array has a size of minimum one.

Only for testing: can you uncomment the if-block where the exception is thrown? Or you can add && count($value) > 0 in line 775 after the is_array($value).

thanosalexander commented 7 years ago

Yes, i uncomment this if (is_array($value)){ $key = array_keys($value)[0]; if (strpos($key, '.') !== false) { $binding = $value[$key]; unset($value[$key]); $key = explode('.', $key)[1]; $value[$key] = $binding; } }

and SUCCESS!! I think it must be added,its usefull