1

In Yii2 I am trying to do an updateAll command, but I cannot for the life of me find how to incorporate a JOIN into this query.

ProjectUser::updateAll(['project_user.is_favorite' => 0],
                       ['project_user.userID' => $methodIDs['user_id'],
                        'project.siteID' => $methodIDs['site_id']
                       ])
                       ->innerJoin('project','project.ID = project_user.projectID')

What I am trying to reach is the above, but Yii2 will ignore the join part and give an error because what remains of the query will NOT recognize the project.siteID column. How can I get this to work?

As alternative I was thinking to just first do a findAll, where the join would work, and update it that way. But how do you update a findAll() result which has multiple records in it?

blackbishop
  • 30,945
  • 11
  • 55
  • 76
Beittil
  • 117
  • 10
  • Ps... Yes I know I actually should fill the variables via the 3rd parameter in the updateAll :P – Beittil Apr 09 '15 at 13:34
  • I cannot believe that completely writing out a custom update query for this (which would actually be an easy one) is the preferred way when you are using the AR system. Or is it? – Beittil Apr 09 '15 at 13:51
  • Ok, I ended up applying the solution from the suggested related question anyway. Guess that was the easiest solution, even tho I think it is does look somewhat 'sloppy'. – Beittil Apr 09 '15 at 14:26

0 Answers0