Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking uniqueness of floats with decimal places does not work #1

Open
ravage84 opened this issue Oct 9, 2013 · 6 comments
Open
Assignees
Labels
Milestone

Comments

@ravage84
Copy link
Owner

ravage84 commented Oct 9, 2013

If you try to check the uniquenes of a float that has decimal places, e.g. 6.3, the validation succeedes, even if there is already a reord with this value.
If you try the same with 6.0 it works.

It seems this problem persists within CakePHP itself because the record containing the value 6.3 also can't be found by using findByFieldX(6.3) (or findByFieldX('6.3') for that matter) where field_x would contain the float value.
If you try to find the record with the value 6.0 the same way, it works.

Tested with a MySQL datasource on Windows 7.

@ghost ghost assigned ravage84 Oct 9, 2013
@dereuromark
Copy link

Does this have to do with float comparison in PHP/MySQL?

@ravage84
Copy link
Owner Author

Probably, I couldn't investigate it more thoroughly yet.
As this is not an issue of this behavior specifically I didn't felt the need to fix it immediatly.

@dereuromark
Copy link

To properly compare float values in PHP, for example, I had to use this once.

@ravage84
Copy link
Owner Author

Since I use Model::iseUnique() in the end this had to be fixed there.
I don't manipulate the values before using the core functionality.

@dereuromark
Copy link

For float values you should usually always have a precision for equality to make sense :)
Maybe you should draw up a test case and go from there.

@ravage84
Copy link
Owner Author

I did/do, see these tests.
I had all the floats in my fixtures with decimal places and encountered the issue when I was writing the tests.
After I changed the fixtures and adjusted the tests to have 6.0 instead of 6.66 the validation worked as expected.
With decimal places the find a the end of Model::isUnique() always returns 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants