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

Fix Select joined table columns (2.8.0) - new version #100

Merged
merged 4 commits into from
Apr 14, 2016

Conversation

belgattitude
Copy link
Contributor

Attempt to fix issue #98

The current fix ensure the the columns of joined tables in a Select object can be excluded from sql string.

Since 2.8.0 the signature of the method join (see Join.php) has slightly changed. The default Select::SQL_STAR is now an array [Select::SQL_STAR].

Unfortunately the check for empty array with the ternary operator below always return SQL_STAR instead of "no columns" :

        $this->joins[] = [
            'name'    => $name,
            'on'      => $on,
            'columns' => $columns ? $columns : [Select::SQL_STAR],
            'type'    => $type ? $type : Join::JOIN_INNER
        ];

This PR changes the way it's tested, but I would love to get some feedback, especially for the strict equality operator... Looks it worked for me and phpunit but It may not be valid for every use case

        if ($columns === [Select::SQL_STAR] || $columns == Select::SQL_STAR) {
            $columns = [Select::SQL_STAR];
        } elseif (!is_array($columns)) {
            $columns = [$columns];
        }

All the best

@belgattitude
Copy link
Contributor Author

Pull request updated...

Think we can get rid of my test for SQL_STAR (see the updated version in Join.php)... As far as I know, the only documented way to 'not' include columns from the joined table is to send an empty array. I also runned the soluble-flexstore unit tests (heavily relies on zend-db) with success.

See also improved functional tests (see SqlFunctionalTest.php)

PS:
I didn't test fully all possible 'undocumented' cases (like sending null or false instead of an empty array, some developers might have done it intuitively on older version). If anyone has ideas I tests different scenarios... Let me know

@h3christophe
Copy link

Thank you ! I can't believe this bug went through like that - I just updated to 2.8.0 and it broke a lot of stuff in my site

I fixed it myself by doing

$this->joins[] = [
            'name'    => $name,
            'on'      => $on,
            'columns' => $columns || is_array($columns) ? $columns : [Select::SQL_STAR],
            'type'    => $type ? $type : Join::JOIN_INNER
        ];

It was not working before because they were testing if $columns was true - but an empty array returns false;

so i check if $columns is true or if it is an array
if not i use the default SQL STAR

@weierophinney
Copy link
Member

I can't believe this bug went through like that

I can; all tests passed locally when I merged, as well as on Travis. There simply weren't tests covering this particular behavior. Considering the enormity of SQL, there will always be edge cases we miss, as we cannot anticipate them all.

Thanks for the detailed reports, and thank you, @belgattitude, for the patch. I'll review and merge in the next day or so, and issue a release when I do.

@belgattitude
Copy link
Contributor Author

@weierophinney you're welcome,

Thanks for all the good work and let me know in case i can help...

Seb

@weierophinney weierophinney added this to the 2.8.1 milestone Apr 14, 2016
@weierophinney weierophinney self-assigned this Apr 14, 2016
@weierophinney weierophinney merged commit d9d0f4c into zendframework:master Apr 14, 2016
weierophinney added a commit that referenced this pull request Apr 14, 2016
Fix Select joined table columns (2.8.0) - new version
weierophinney added a commit that referenced this pull request Apr 14, 2016
weierophinney added a commit that referenced this pull request Apr 14, 2016
weierophinney added a commit that referenced this pull request Apr 14, 2016
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.

3 participants