Commit
Fix validateUnique() causing errors when used as a validator with additional scope. Fixes #5652
- Loading branch information
There are no files selected for viewing
10 comments
on commit 28462ca
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You switched the arguments, but the docs are still wrong (doc block).
I tried using scope but now it doesn't work anymore. scope is in $context['scope']
not $options['scope']
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test case shows scope working as a validator though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text case might work because the strict check applies for null being passed, If it is an empty array or alike it might be different. At least in my real life scenario the order was wrong.
I hotfixed it merging the params context and option for now, but we should probably into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used RC1 and got the error here. Then I updated to RC2, now everything seems to work at first, but it does not consider the scope I assign the rule. It marks my email as invalid even though it is unique (to that scope, but not globally in the table).
Below is the code I have added to my table model. Am I stupid and doing something wrong? Or is this a bug? Best regards Jon
->add('email', 'unique', [
'rule' => [
'validateUnique', [
'scope' => 'survey_id']],
'provider' => 'table'])
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That looks like it should work based on the tests cases. What queries is the validation rule emitting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the query that is only present when I have the rule activated, no notion of survey_id at all.
SELECT 1 AS `existing` FROM participants Participants WHERE email = '***@***.**' LIMIT 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. I will take another look. The tests could be wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were you able to replicate the problem? Or do you need more input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and fix has been merged into 3.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wonderful! Thanks for the quick remedy of this problem, and for CakePHP in all. Its really a great framework! =D
Not sure if that joggling is good per se.
Maybe we should always attach the context as last argument to be safe?
Other validation methods could follow the same pattern: