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

Generating CRUD with via() and many-to-many relations gives an exception. #298

Open
KevinVanH opened this issue Nov 3, 2023 · 0 comments
Assignees

Comments

@KevinVanH
Copy link

KevinVanH commented Nov 3, 2023

In the following line

$pivotName = Inflector::pluralize($generator->getModelByTableName($relation->via->from[0]));

it tries to access $relation->via->from[0]. However, this does not exist. Via is an array with keys 0, 1, 2 as shown below. The following error is thrown when generating the CRUD:

PHP Warning 'yii\base\ErrorException' with message 'Attempt to read property "from" on array'

$relation->via looks like this:
image

It seems like this happens only with many-to-many relations when using via(). (JUNCTION_RELATION_VIA_MODEL)

Changing $relation->via->from[0] to $relation->via->from[0] ?? $relation->via[0] seems to fix it, but I'm not sure if this is correct.

Giiant 0.15.0-beta2
Yii2 2.0.49.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants