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 reverse join inconsistencies and defaults #802

Merged
merged 11 commits into from
Dec 11, 2020

Conversation

DarkSide666
Copy link
Member

@DarkSide666 DarkSide666 commented Dec 10, 2020

Also explains, fix #799

tests/JoinArrayTest.php Outdated Show resolved Hide resolved
src/Model/Join.php Outdated Show resolved Hide resolved
[$this->foreign_table, $this->foreign_field] = preg_split('/\.+(?=[^\.]+$)/', $this->foreign_table);
if ($this->reverse === true) {
if (isset($this->master_field) && $this->master_field !== $id_field) {
throw (new Exception('You are trying to link tables on non-id fields. This is not implemented yet'))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
throw (new Exception('You are trying to link tables on non-id fields. This is not implemented yet'))
throw (new Exception('Joining tables on non-id fields is not implemented yet'))

Copy link
Member

Choose a reason for hiding this comment

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

I wonder what is the main issue

Copy link
Member Author

Choose a reason for hiding this comment

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

If i remember correctly that was because we can't rely on fields if at least one of them is not unique id field. Something along these lines. Anyway this PR tries not to solve that.

Copy link
Member

@mvorisek mvorisek Dec 10, 2020

Choose a reason for hiding this comment

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

we can't rely on fields if at least one of them is not unique id field.

is this important if all work is done by SQL?

Copy link
Member Author

Choose a reason for hiding this comment

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

All work is not done by SQL I think. At least that wasn't the case time ago. It's important in what order you insert records (reverse or not) and afterwards you have to insert respective record in other table too.

Anyway I specifically didn't address that here!
This PR is just about adding more tests and a bit normalizing method how we define reverse joins. Before there was only a one and not intuitive way how to define them. And as soon as you, for example, explicitly said that join is reverse or even set master-field='id' yourself (same as default value set by ATK) it started to fail with You are trying to link tables on non-id fields. This is not implemented yet exception.

Copy link
Member

@mvorisek mvorisek Dec 10, 2020

Choose a reason for hiding this comment

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

I specifically didn't address that here

but 1/2 of the added LOC are exceptions for that, better to solve the ID limitation if possible, I am ok with merging this, but with proper issue for that limitation and adding a link to it to the code (like I tried with this PR, replace them)

Copy link
Member Author

@DarkSide666 DarkSide666 Dec 10, 2020

Choose a reason for hiding this comment

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

These two added expected exceptions in tests was added because previously tests was wrong. They "tested" cases which was not supported, but didn't get proper exception because of slightly wrong exception implementation in Join class (which is now fixed there).
OK created issue #803 for that and will see what can be done but outside of this PR.

src/Model/Join.php Outdated Show resolved Hide resolved
tests/JoinArrayTest.php Outdated Show resolved Hide resolved
tests/JoinSqlTest.php Outdated Show resolved Hide resolved
src/Model/Join.php Outdated Show resolved Hide resolved
Copy link
Collaborator

@georgehristov georgehristov left a comment

Choose a reason for hiding this comment

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

LGTM

@DarkSide666 DarkSide666 merged commit b9a1ceb into develop Dec 11, 2020
@DarkSide666 DarkSide666 deleted the feature/join-save-bug branch December 11, 2020 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reverse join not saving
3 participants