Issue
Trying to update some rows based on related data, using matching. But only the "where" clause is working. The "matching" is ignored!
Am I, doing something wrong?
$tbTU = TableRegistry::get('TaskUsers');
$query = $tbTU->query()
->where([
'TaskUsers.service_order_id' => $so_id,
'TaskUsers.status IN' => [0, 4, 7, 9],
])
->contain(['Tasks'])
->matching('Tasks', function($q) {
return $q->where([
'Tasks.task_type IN' => [1, 4, 5]
]);
});
return $query
->update()
->set([
'status' => 3,
'user_id' => NULL,
'modified' => Time::now()
])
->execute();
Thanks!!
Solution
It seems that the answer to your question is no, according to this issue
As @ndm says in the comments you can use a subquery depending on your DBMS
I would do something like this:
$subquery = $this->TaskUsers->Tasks->find()
->select(['id'])
->where(['Tasks.task_type IN' => [1, 4, 5]]);
$tbTU->query()
->where([
'TaskUsers.service_order_id' => $so_id,
'TaskUsers.status IN' => [0, 4, 7, 9],
'TaskUsers.task_id IN' => $subquery
])
});
Answered By - arilia
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.