-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
BaseModel/Model - Attempt to rework escape parameter #4072
BaseModel/Model - Attempt to rework escape parameter #4072
Conversation
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.
Well, for 4.0.x I would rather merge this. 4.1 is a different story, but I would like to hear other people's opinions about it.
I know we shouldn't introduce BC changes into a minor version, but it feels like an improvement I'd shut my eyes for (if it would come with a good docs update).
Dubious elegance $db->escape = false;
$db->insert([]);
//instead
$db->insert([], true, false); A class property is usually added to persist state. But you are resetting its value with every insert/update query. |
The class property is to keep state which is set in insert/update methods and handle this state in doInsert/doUpdate methods where is reseted after getting the value. It works completely fine as is but the issue here is that public method definititons were modified when BaseModel was introduced. So having those changes will break stuff if there are custom model classes where this methods are overriden |
Oh, please don't reinvent the wheel. |
I think @iRedds have a good point here. Seems like |
@iRedds the issue here is that QueryBuilder is called in doInsert/doUpdate but the value have to be processed in insert method to get the data from tempData which is only done if insert/update is called with empty data. Since the parent insert/update methods handle conversion to array if data is empty it will throw an exception so we have to get the date from tempData before passing on to baseModel method. This is all due to set method from QueryBuilder being captured in model so that data can be validated. So the escape parameter cannot be removed unless we have a way to pass the tempData['escape'] to doInsert/doUpdate It can be done with tempData directly but the value should only be passed if insert/update was called with empty data so in such case we could instead of setting $this->tempData to empty array in insert/update we can unset $this->tempData['data'] and keep $this->tempData['escape'] and then get the escape value from tempData and reset it out in the do method |
Thanks for explanation @najdanovicivan. Maybe we could make |
OMG. OMG. We will all die. =) In my current CI3 project, I am using a base model that implements search, save, delete and event handling methods. There are 400 lines of code in the model, not around 3000 like CI4. Does the code work without your changes? Works. But it seems to me that it is better to completely revise the classes and remove this insert + parent::insert + doInsert. |
@iRedds I have MongoDB driver for which is mandatory to use BaseModel The idea behinde BaseModel/Model is to separate the DB stuff from the other things model do. Validation, Pager, Dates .., |
There is already a |
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.
Looking at the version in master
, I think using the class property is our only way for Model::doInsert
to consume the $escape
var from Model::insert
.
Thanks @paulbalandan I missed that. |
Description
Here is one way of keeping escape parameter outside of method definitions. But the existing solution is much more elegant
@michalsn What's your opinion on this one ?
Should we keep the existing implementation and just update the docs or should this one be merged
Checklist: