-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
CheckNull option for IsUnique #8621
Conversation
No, this is bad. I think at the data storage level this is a problem. MySQL for example does not support null for unique indexes. It just ignores it. If a column allows null and has a unique index it can contain many nulls. You don't gain any index performance by using null either. What ever problem it was that you were originally trying to solve. There was probably was a better way to solve it than testing for unique null. |
@thinkingmedia I'm struggling to understand your argument.
AFAIK the SQL standard says that you cannot have
What does this have to do with this option? How can allowing an option for
True but again, I don't see how this is relevant? This is adding an option to the validation stage before data insertion, so why can we not offer an option that MySQL does not? There are multiple threads calling for MySQL to support this, so it's clearly a wanted feature but still, I don't see how it should affect what Cake offers? If Cake only offered validation options that were available in MySQL, then surely there would be no need for the Cake Validation stage in the first place?
I'm all up for suggestions. AFAIK, this is the best option for someone who wants |
@JayPHP first, I'm apologizing if you found my comment was to critical of your work. I understand that these pull requests take a lot of time to make, and I didn't mean to sound like I was slamming the door on the PR. I don't have authority here to reject PRs and was just stating an opinion, and maybe not a very good one at that. I'm of the opinion that We can count things in the dataset with So I worry that this encourages the usage of Again, this is just my opinion. It does change often ;) |
@thinkingmedia This is my first contribution so I appreciate any feedback I can get, really.
Now I completely understand what you mean; It looks like PHP is more on the value side? http://php.net/manual/en/language.types.null.php however, SQL (like you say)...
So I guess I'm torn but leaning towards your opinion more as this method is fairly db based |
As the one suggesting that possible "solution" for the given "problem", without putting the root of the problem to question, and possibly offering solutions that don't require such controversial constraints, let me add my tree fiddy... AFAIR, MySQLs BDB engine supported With respect to that historical behavior, being able to represent this in the form of an application rule might come handy for some SQL Server peeps, whether this justifies core feature relevance however is of debatable nature. Rethinking it, I think I'd now possibly tend more towards, nah, might not be an overly good idea, enforcing standards on that level of the abstraction layer might be better. Making the rule more extensible may be a compromise, so that people could easily modify the conditions without having to reimplement the whole rules logic. |
@@ -63,6 +64,15 @@ public function __invoke(EntityInterface $entity, array $options) | |||
} | |||
} | |||
|
|||
if ($checkNull) { | |||
foreach ($conditions as $key => $value) { |
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.
Couldn't this be done in the _alias()
method that is called on line 57?
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.
@markstory So add another parameter to the alias method? (Currently the only parameter is $alias
)
Agreed with @lorenzo that this isn't required. A simple note in the docs to say that |
@chinpei215 I spoke to @lorenzo in slack. Sorry it doesn't make sense, i'll try and explain a bit better below; So, while using Now, lets say I have the below entry in my database;
If I try to save the above entry again, the So the However from speaking to Lorenzo in slack + the above discussions, I don't think there's much support for it, that's why I closed :) |
@JayPHP Thank you for explaining your issue. But I knew that when this PR opened. My English might be bad. I wanted to say "I think this PR is not bad". Personally, I wouldn't use this feature. But I think that some people would need this feature, as I have seen some applications using a datetime field for soft delete. And thank you for letting me know about the discussion on slack. Although I am not good at English, but if you closed this PR for the reason of naming, what about
|
@chinpei215 Ah apologies, I misunderstood your comment. Alright I'll re-open and improve the request via @markstory comments. |
@@ -53,6 +53,11 @@ public function __invoke(EntityInterface $entity, array $options) | |||
return true; | |||
} | |||
|
|||
$permitMultipleNulls = true; | |||
if (isset($options['permitMultipleNulls'])) { |
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.
Naming the option allowMultipleNulls
would be better for consistency since "allowFoo" is used at other places in the framework.
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.
@ADmad @chinpei215 No problem :) Updated. |
@@ -53,6 +53,11 @@ public function __invoke(EntityInterface $entity, array $options) | |||
return true; | |||
} | |||
|
|||
$allowMultipleNulls = true; | |||
if (isset($options['allowMultipleNulls'])) { |
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 think those strings should not be magic strings but class constants.
This way they can be used from outside without the risk of typos (IsUnique::ALLOW_MULTIPLE_NULLS
etc).
We should be doing this more often in general with those option keys available per class IMO.
Would do others think?
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.
@dereuromark I guess it's bad practise to presume that the user won't accidentally enable this, so +1 from me. If others agree, I don't mind trying to change it to a constant.
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.
@dereuromark Theoretically, I think you are right. But as you know, we are using string literals in many places. For example:
$validator
->add('title', 'notEmpty', [
'rule' => 'notEmpty',
'message' => __('You need to provide a title'),
]);
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.
@chinpei215 It is still never too late to start somewhere :)
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.
@dereuromark Sure. But it would be better to discuss it apart from this PR. The above line also can be changed after discussion :)
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 am fine with that :)
Thanks! |
cake 3.2.X need to these changes :) |
@saeideng Its a new feature, we often put new features into 3.next. |
thanks mark.
|
@markstory i dont talk about |
Can you open a ticket for what you have found to be a bug? please make sure to explain how to reproduce it |
@saeideng Well both the original issue and pull request positioned these changes as a new features. |
This is a suggestion for issue #8620
PHPUnit tests;