Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Conversation

OleksandrBonar
Copy link
Contributor

@OleksandrBonar OleksandrBonar commented Nov 12, 2018

This fix possible delete items from aliased table through TableGateway class

@OleksandrBonar OleksandrBonar changed the base branch from develop to master November 12, 2018 14:37
Copy link
Member

@michalbundyra michalbundyra left a 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.

@OleksandrBonar
Copy link
Contributor Author

OleksandrBonar commented Nov 13, 2018

This fix possible delete items from aliased table through TableGateway class.
@webimpress Done

@@ -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'])
Copy link
Member

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.

Copy link
Contributor Author

@OleksandrBonar OleksandrBonar Nov 15, 2018

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

Copy link
Member

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?

Copy link
Contributor Author

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!

Copy link
Member

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.

Copy link
Contributor

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!

@OleksandrBonar
Copy link
Contributor Author

@malukenho, @webimpress what next, guys?

@michalbundyra
Copy link
Member

@OleksandrBonar

I'd really like to help, but I am not the maintainer of the library... You have to be patient :)
Please add more test to cover all changes you made. See my comment above.

@OleksandrBonar
Copy link
Contributor Author

@webimpress, @ezimuel Tests have already been added. What need to add?

@michalbundyra
Copy link
Member

@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 :)

@OleksandrBonar
Copy link
Contributor Author

@webimpress Method testDeleteWithArrayTable in file test/unit/TableGateway/AbstractTableGatewayTest.php must catch an exception

@michalbundyra
Copy link
Member

@OleksandrBonar

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.

@OleksandrBonar
Copy link
Contributor Author

I apologize. Looking at a fresh look at the code, I realized that checking the table variable was overly complicated.

@OleksandrBonar
Copy link
Contributor Author

@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

Copy link
Member

@michalbundyra michalbundyra left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add space after *.

test/unit/TableGateway/TableGatewayTest.php Show resolved Hide resolved
@OleksandrBonar
Copy link
Contributor Author

@webimpress done! )

Copy link
Member

@michalbundyra michalbundyra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@ThomasRo
Copy link

ThomasRo commented Jan 4, 2019

The provided solution is consistent with the one for the update statement (method AbstractTableGateway::executeUpdate), but i do not like both of them.
They both disable the possibility to use aliases with update and delete statements, while indeed aliases make sense, in particular if you make use of additional joins with your update or delete statements. zend-db natively does allow joins in update statements; some RDBMS do also allow joins in delete statements and the zend sources can easily extended to make use of them.
I would suggest to fix Zend\Db\Sql\AbstractSql::resolveTable in order to support aliases in all statements.
Overwriting attributes (and losing information) while executing a statement, does not feel right. Furthermore a statements gets build, which is different from that one, which you get by calling AbstractSql::getSqlString (for debugging purposes) because there, the overwriting does not take place.

@michalbundyra
Copy link
Member

@ThomasRo Can you provide test case, please? Then we will try to find solution to resolve both issues.

@ThomasRo
Copy link

ThomasRo commented Jan 8, 2019

@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

@OleksandrBonar
Copy link
Contributor Author

@ezimuel updates published

@OleksandrBonar
Copy link
Contributor Author

bump

@OleksandrBonar
Copy link
Contributor Author

@malukenho please review and approve or decline these changes

@michalbundyra
Copy link
Member

Thanks, @OleksandrBonar!

michalbundyra added a commit that referenced this pull request Dec 31, 2019
…teFromAliasedTable

Delete from aliased table
michalbundyra added a commit that referenced this pull request Dec 31, 2019
michalbundyra added a commit that referenced this pull request Dec 31, 2019
@michalbundyra michalbundyra merged commit ee1f6d9 into zendframework:master Dec 31, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants