-
-
Notifications
You must be signed in to change notification settings - Fork 6.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
Added QueryInterface::emulateExecution()
#12708
Conversation
* @return $this the query object itself | ||
* @since 2.0.11 | ||
*/ | ||
public function cancel(); |
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 the name of the method isn't OK since we as users do not clearly separate actual SQL query and getting the result. I propose using another name such as skipQuery()
(not sure it's the best one).
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.
Renamed to preventExecution()
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.
another possibility is 'simulate'
QueryInterface::cancel()
QueryInterface::preventExecution()
Still looks like a hacky solution but I can't suggest anything better... |
QueryInterface::preventExecution()
QueryInterface::emulateExecution()
Oh! Now I like the naming. |
emulate is even better |
I've reviewed it. I don't know with this solution. It works but it seems to be an overkill for realizing the objective 'DataProvider preventing search query execution'. Aren't there any other solutions out there that are less obtrusive? |
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.
Good changes! Need a CHANGELOG and UPGRADE note. Will add them myself. Merging now.
@@ -1312,4 +1312,69 @@ public function testAttributeAccess() | |||
$baseModel = new ActiveRecord(); | |||
$this->assertFalse($baseModel->hasProperty('unExistingColumn')); | |||
} | |||
|
|||
public function testEmulateExecution() | |||
{ |
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.
could assert here that the customer table is not empty, otherwise the test would pass without emulateExecution()
to work
Added
QueryInterface::emulateExecution()
, which allows preventing of the actual query execution.This allows to cancel
DataProvider
preventing search query execution in case search model is invalid:This also fix unecessary query in case of
via()
usage. See #12390.Note: this PR produces minor BC break as it alters
yii\db\QueryInterface
, however the implementation of new method is present atyii\db\QueryTrait
- thus it is less likely to produce a trouble.