-
Notifications
You must be signed in to change notification settings - Fork 122
Delete from aliased table #342
Delete from aliased table #342
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.
@OleksandrBonar Please add test case to cover your changes and description why the change is needed.
This fix possible delete items from aliased table through TableGateway class. |
@@ -439,7 +439,10 @@ public function deleteWith(Delete $delete) | |||
protected function executeDelete(Delete $delete) | |||
{ | |||
$deleteState = $delete->getRawState(); | |||
if ($deleteState['table'] != $this->table) { | |||
if ($deleteState['table'] != $this->table | |||
&& (is_array($deleteState['table']) |
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 you want to have here ||
instead of &&
. This should be covered in tests. I can't see related test to this change.
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.
In "executeSelect" method the same logic and it works
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.
Hm... So I guess in both places it's wrong. What do you 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.
executeSelect for aliased table it works!
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.
@OleksandrBonar You are missing test to cover that change.
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.
@OleksandrBonar can you provide the unit test mentioned by @webimpress? Thanks!
@malukenho, @webimpress what next, guys? |
I'd really like to help, but I am not the maintainer of the library... You have to be patient :) |
@webimpress, @ezimuel Tests have already been added. What need to add? |
@OleksandrBonar I was saying that there are missing test cases for the condition you've updated where we should get exception. I have some "wrong feelings" about that conditions and tests will verify them :) |
@webimpress Method testDeleteWithArrayTable in file test/unit/TableGateway/AbstractTableGatewayTest.php must catch an exception |
As I can see that method tests just positive scenario, without the exception. I'd like to have scenarios when as the result we should get the exception so something with: $this->expectException(...);
$this->expectExceptionMessage(...); and it is not there, but it should be. |
I apologize. Looking at a fresh look at the code, I realized that checking the table variable was overly complicated. |
@webimpress In the delete method, when the table name is an array with an alias, the original name is retrieved to fulfill the query. Then the alias is restored. This situation is tested in the file TableGatewayTest.php |
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.
@OleksandrBonar It makes much more sense right now. Please see my comments, update PR and then it will be all good for me. Thanks! 👍
@@ -260,4 +261,66 @@ public function testUpdateShouldResetTableToUnaliasedTable($tableValue, $expecte | |||
$state['table'] | |||
); | |||
} | |||
|
|||
/** | |||
*@dataProvider aliasedTables |
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.
Please add space after *
.
@webimpress done! ) |
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.
LGTM 👍
The provided solution is consistent with the one for the update statement (method AbstractTableGateway::executeUpdate), but i do not like both of them. |
@ThomasRo Can you provide test case, please? Then we will try to find solution to resolve both issues. |
@webimpress I have tried to, but came across many impacts to other statements so that the necessary efforts are to big... Since i won't deliver a better solution, i go with the one of @OleksandrBonar |
@ezimuel updates published |
bump |
@malukenho please review and approve or decline these changes |
Thanks, @OleksandrBonar! |
…teFromAliasedTable Delete from aliased table
This fix possible delete items from aliased table through TableGateway class