-
Notifications
You must be signed in to change notification settings - Fork 46
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
Model::setNull() - Allow field value unset #569
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #569 +/- ##
=============================================
+ Coverage 86.27% 86.75% +0.47%
- Complexity 1232 1234 +2
=============================================
Files 28 28
Lines 2718 2740 +22
=============================================
+ Hits 2345 2377 +32
+ Misses 373 363 -10
Continue to review full report at Codecov.
|
a34afab
to
069d01d
Compare
b35eaf1
to
68b5ae7
Compare
|
||
// invalid value for set() - normalization must fail | ||
$this->expectException(\atk4\data\Exception::class); | ||
$m->set('c', null); // @TODO even "b"/mandatory field should fail! |
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.
@DarkSide666 Am I right, that with "b" field / mandatory field this should fail too?
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 b
(mandatory
) should also not allow null
value, but allows empty string value.
Basically mandatory
should be called notNull
and required
should be called notEmpty
, but changing these property names would be big compatibility break and a lot of code to refactor again in actual projects which use atk4/data :(
Also one of these properties (not sure now which one it was) is more like UI specific property. I guess it's required
(notEmpty) one, but again, changing that will break a lot of projects.
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.
@DarkSide666 Yes, I always need to look at the phpdoc for this. notNull
and notEmpty
will be perfect - ok to refactor? This project is still in very early stage. If we want to make this project big, I think we should not wait with these changes.
To the issue - can you propose a PR with fix before this is merged? The mandatory
normalization/validation currently does not work.
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 notNull
and notEmpty
would be perfect names for these properties, but changing that will break almost every single data model we have in all our projects :(
Can we change them in at least semi-compatible manner? Maybe introduce isNotNull()
and isNotEmpty()
methods for that and also use both property names just to keep some compatibility.
On the other hand of course it would be much better (cleaner code) to just change these property names everywhere. Also would like to have @romaninsh input on this. Sadly he's quite hard to catch lately.
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.
@DarkSide666 The current design choose is actually a slightly different - required
does not allow everything that evalueated with empty()
to true, thus even not null, I understand that it may be handy to set one required
property, but it is horrible design choice as mandatory
can be false even if the field is effectively mandatory
.
Rejecting empty values but still allowing null may be perfectly valid, at least in atk4/data
.
Wdyt and what is your prefference? Two bool properties notNull
and notEmpty
("empty" excl. null) or one enum property for all 4 possibilities?
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 do not see 4 possibilities here - only two.
- only restrict
null
values - everything else (empty string, zero, false etc.) is allowed - restrict
null
and empty values - do not allow empty string, false, (not sure about this - i think zero should be allowed - it's legit value) zero, empty array etc.
Also there was idea that actually one of these properties more belong to UI than Data level, but it would be quite painful to move it somewhere else because of backward compatibility...
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.
@DarkSide666 - no restriction, prevent null, prevent empty but allow null, prevent null and empty
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.
prevent empty but allow null - I can't imagine of any use-case for this.
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.
@DarkSide666 In data it is very common - null has meaning of N/A, not set yet, while empty means empty value is desired - and not always empty value should be allowed.
2399d96
to
155fe0c
Compare
|
||
// invalid value for set() - normalization must fail | ||
$this->expectException(\atk4\data\Exception::class); | ||
$m->set('c', null); // @TODO even "b"/mandatory field should fail! |
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 b
(mandatory
) should also not allow null
value, but allows empty string value.
Basically mandatory
should be called notNull
and required
should be called notEmpty
, but changing these property names would be big compatibility break and a lot of code to refactor again in actual projects which use atk4/data :(
Also one of these properties (not sure now which one it was) is more like UI specific property. I guess it's required
(notEmpty) one, but again, changing that will break a lot of projects.
Please add:
Besides that |
See above, I want (and actually did), but the current implementation is broken... |
@DarkSide666 As this PR is complete, you can merge it and solve the |
OK I agree. |
Fix #542
Use case: https://github.com/atk4/ui/blob/06fc859685cdf5f9f3d19772f4305e9eac2d99c0/src/FormField/Lookup.php#L435