active-record icon indicating copy to clipboard operation
active-record copied to clipboard

Ignore unnecessary joinWiths

Open dynasource opened this issue 8 years ago • 3 comments

Currently, \yii\db\ActiveQuery allows you to join the same relations twice (or more) with joinWith. Because of that, the DBMS will complain as you are doing multiple joins on the same table.

I am wondering why this isnt fixed with a simple patch to

  • https://github.com/yiisoft/yii2/blob/master/framework/db/ActiveQuery.php#L429

in which $joinWith gets the relations mapped by their relation $key. This prevents double insertions and those problematic and unnecessary exceptions when you are ensuring that a joinWith is executed.

dynasource avatar Jul 21 '17 12:07 dynasource

How do you want to fix it? Joining the same table is fine. For example, if you need N levels of adjacent list at the same time.

samdark avatar Jul 21 '17 12:07 samdark

by their $alias as these also have to be unique in the DBMS.

dynasource avatar Jul 21 '17 12:07 dynasource

Yes. That may work.

samdark avatar Jul 21 '17 16:07 samdark