Skip to content
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

Fix a bug in the join generator when same table is present multiple times #11690

Merged
merged 3 commits into from May 14, 2017

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented May 12, 2017

See the test below. Before this fix it would generate a join like

log_visit AS log_visit
LEFT JOIN log_conversion AS log_conversion ON log_visit.idvisit2 = log_conversion.idvisit2
LEFT JOIN log_conversion AS log_conversion ON log_visit.idvisit = log_conversion.idvisit

instead we want to have only

log_visit AS log_visit
LEFT JOIN log_conversion AS log_conversion ON log_visit.idvisit2 = log_conversion.idvisit2

Because log _conversion was already joined we don't need to join it again on different logic because there was no specific join logic specified for log_conversion so we can re-use an existing join and prevent an error message that eg log_conversion is not unique.

@tsteur tsteur added Bug For errors / faults / flaws / inconsistencies etc. Needs Review PRs that need a code review labels May 12, 2017
@tsteur tsteur added this to the 3.0.4 milestone May 12, 2017
'log_visit',
array('table' => 'log_conversion', 'joinOn' => 'log_visit.idvisit2 = log_conversion.idvisit2'),
'log_conversion'
));
Copy link
Member

Choose a reason for hiding this comment

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

Haven't had a closer look at the usage of the JoinGenerator, but the result might still be invalid if the order changes like this

        $generator = $this->generate(array(
            'log_visit',
            'log_conversion',
            array('table' => 'log_conversion', 'joinOn' => 'log_visit.idvisit2 = log_conversion.idvisit2')
        ));

That would still result in a duplicate LEFT JOIN. Is that something that could happen, or can we ignore that?

Copy link
Member Author

@tsteur tsteur May 12, 2017

Choose a reason for hiding this comment

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

I know, I tried to implement it but won't be trivial. We could rather create a new issue for it. Eg when array is like

array(
            'log_visit',
            'log_conversion',
            'log_link_visit_action',
            array('table' => 'log_conversion', 'joinOn' => 'log_link_visit_action.idvisit2 = log_conversion.idvisit2'),

Then I can't simply use the join condition of the second log_conversion array on the first log_conversion table since it might reference a table that is only joined later. Also I cannot remove the first log_conversion since it might be used in a join before the other log_conversion comes.

Copy link
Member Author

Choose a reason for hiding this comment

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

FYI: Just pushed an update to instead throw an exception when this happens with detailed information where it happens and why. As solving it won't be trivial and is easier to instead just re-structure the array order for now if / when needed

Copy link
Member

Choose a reason for hiding this comment

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

+1 merging this fix now and creating a new issue for the rest.

Copy link
Member Author

Choose a reason for hiding this comment

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

Created #11697

@sgiehl sgiehl removed the Needs Review PRs that need a code review label May 12, 2017
@tsteur
Copy link
Member Author

tsteur commented May 13, 2017

Pushed some more changes re review feedback

@tsteur tsteur merged commit a49768f into 3.x-dev May 14, 2017
@tsteur tsteur deleted the joingeneratorfix branch May 14, 2017 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants