-
Notifications
You must be signed in to change notification settings - Fork 48
Fix system condition handling #692
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
Closed
Closed
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
030b5e0
[update] introduce and use Scope::create
georgehristov e9e6dfb
[update] introduce Condition::isTraversing
georgehristov 0cc4be9
[fix] introduce AbstractScope::setSystem
georgehristov a332d86
[fix] use correct operator
georgehristov 7db95b1
Revert "[update] introduce Condition::isTraversing"
georgehristov d12f1cc
Revert "[update] introduce and use Scope::create"
mvorisek cbdb1c9
Merge branch 'develop' into fix/introduce-system-condition
mvorisek 50c8d75
fix merge
mvorisek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 whole code must be moved into Model under specific method
if this is currently used in refs etc., we must investigate, probably we even want to call this special method when traversing (thru refs)
Uh oh!
There was an error while loading. Please reload this page.
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.
Model condition in ATK is integral part of the model as the data can be scoped down using
Model::addConditionorModel::scope()->addCondition. SoaddConditionis the special method we use.This present flag routine is necessary as it makes sure:
It is not about reference records only. Consider a model
Peoplewith fieldGender. You can define a sub-scope model classMenwhen adding conditiongender = 'male'in init method. So if you create new record in Men the Gender field will be set automatically to 'male' and having it as system field you cannot set it to anything else, which is correct.The other not-defining way to apply condition is on the query directly after we merge my refactor on queries:
$people->toQuery('select')->where('gender', 'male');or when I introduce the
Model\QueryTrait:$people->where('gender', 'male');This does not change the scope on
$people. It just returns an iterator for all men.If you find it more descriptive I can change the
setSystemtosetSystemFieldIfDefiniteand we merge this fixThere 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 know this. I will summarize shortly:
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 explaining above that
addConditionis this explicit method you are requesting.It implicates that the model is being changed (not for querying only) as you addCondition to the model
The 'not explicit' method is
Model::whereThere 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.
Look at it differently - I use STANDARD addCondition for ex. for event, let say "party".
If want to restrict user to only one event - "party" - then I add condition "= 'party'".
With your proposal, the event field will behave absolutely differently vs. if I set "in('party')". That is unacceptable.
So maybe we mixed 2 things together:
a) there was some default/system behaviour when some definitive condition was set which was broken as we allow deeper nesting of not only and conditions now - this PR may solve this, even I think not optimally, as Condition can be made later made not always true
b) implicit change of Field with side effect to other code - described above, we MUST prevent this
Uh oh!
There was an error while loading. Please reload this page.
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.
So in this regard I would suggest to approach the other way:
event in ('party', 'gala')then no other values will be accepted for the event field and validation exception will be thrown.I have the validation routine for Scope but I removed it for the basic functionality.
We also need opinion and input on this from @romaninsh and @DarkSide666
Uh oh!
There was an error while loading. Please reload this page.
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 may be leaking (like if we compare some secret) and not sure if you meant system as well
I propose to NOT set any Field param based on condition.
I think, that system&default is needed for refs or in definitive model scoping in general, but this should be fully intended by the user and the current approach is for
=only (as default can have only one value), thusinin your later example can not be handled or even=when defined with expr.If you do not have a full SQL parser like DSQL (which parses fully, but it quite limited on the other side), then you can not have a validation routine.
To move this thread forward I propose to implement:
addCondition()+ update Field (default/system, like now)or
so I stay very very firm to implement is using special method in Model - which I belive is clean, quite BC (100% in refs) and later, we might introduce extended concept - but probably never redefine Field from Condition/Scope