gearbox-solutions / eloquent-filemaker

A Model extension and Eloquent driver for Laravel connecting to FileMaker through the Data API
https://gearboxgo.com
MIT License
54 stars 16 forks source link

whereNot() method not working properly? #49

Closed orochefort closed 5 months ago

orochefort commented 1 year ago

Dependencies

Description of the issue:

Is it me or the whereNot() method doesn't seems to work properly. I mean that it doesn't seems to omit the records.

I'm using it to validate that an email is unique with a Validator() when a user try to modify his email address (we don't want to have multiples accounts with the same email address).

Validator::make($input, [ 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'email', 'max:255', Rule::unique('users')->whereNot('id', $user->id)], ])->validateWithBag('updateProfileInformation');

I also tried to use the shortcut method ignore() but that doesn't works too :

Validator::make($input, [ 'name' => ['required', 'string', 'max:255'], 'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore('id', $user->id)], ])->validateWithBag('updateProfileInformation');

Smef commented 1 year ago

I haven't done a test for this, but I suspect this could how @ is a special character in FM find requests, and searches on an email address require a bit of special handling. Can you try this with a non-email field and see if this works for you?

orochefort commented 1 year ago

Thank you for the reply.

Yes, I already manage the fact that "@" is a wildcard search character in FM. I'm escaping it before executing the search. Something like this :

str_replace('@', '\\@', $myemail);

That works great in other parts of my code which don't involve the use of the whereNot() method.

As requested, I did a couple of tests to narrow down the problem. My conclusion is that whereNot() acts exactly as the where() method. It's like doing a search in FileMaker and the "omit" option having no effect. You can easily replicate the problem by doing a simple search with the FM facade. Example :

$data = FM::table('users') ->whereNot('user_id', '>', 99) ->get(); dd($data);

Normally it would return users with IDs between 1 and 99, but instead it returns all users with IDs greater than 99.

Smef commented 5 months ago

I believe this is resolved in 2.0, which should be releasing soon.