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

update BaseActiveRecord #17197

Closed
wants to merge 3 commits into from
Closed

update BaseActiveRecord #17197

wants to merge 3 commits into from

Conversation

Bhoft
Copy link
Contributor

@Bhoft Bhoft commented Mar 8, 2019

Update BaseActiveRecord so that link() and unlink() supports viaRelation on conditions.

Q A
Is bugfix? yes
New feature? no
Breaks BC? no
Tests pass? yes/no
Fixed issues #17174

Update BaseActiveRecord so that link() and unlink() supports viaRelation on conditions.

yiisoft#17174
@samdark samdark added the pr:request for unit tests Unit tests are needed. label Mar 8, 2019
@yii-bot
Copy link

yii-bot commented Mar 8, 2019

Thank you for putting effort in the improvement of the Yii framework.
We have reviewed your pull request.

In order for the framework and your solution to remain stable in the future, we have a unit test requirement in place. Therefore we can only accept your pull request if it is covered by unit tests.

Could you add these please?

Thanks!

P.S. If you have any questions about the creation of unit tests? Don't hesitate to ask for support. More information about unit tests

This is an automated comment, triggered by adding the label pr:request for unit tests.

@samdark samdark added the type:bug Bug label Mar 8, 2019
added is_array check because ViaRelation->on could also be a string as it is in the ActiveRecordTest::testJoinWithSameTable
@Bhoft
Copy link
Contributor Author

Bhoft commented Mar 11, 2019

I have realized that the On Condition of the ActiveQuery could also be a String.
My solution only handles the conditions by array.
I am not sure how a "string" condition could be split up into parts to fill the $columns array.
Maybe its enough to throw an error if its an string.
So at least the condition via arrays are handled correctly.

for unlink() something like this would work because it used internally updateAll and deleteAll

if (!empty($viaRelation->where)) {
    $columns = ['and', $columns, $viaRelation->where];
}
if (!empty($viaRelation->on)) {
    $columns = ['and', $columns, $viaRelation->on];
}

but for link() i have no clue how i could guess the preset values for the insert.
If on is an array its not a big deal. But for relations e.g. with an additional where as a string...

But as for link() there is already a possibility to preset the columns of the junktion table both could be linked and unlinked.

@bizley
Copy link
Member

bizley commented Mar 22, 2021

Closed in favor of #18564

@bizley bizley closed this Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:request for unit tests Unit tests are needed. type:bug Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants