Is there any way to db_update()
for the following query?
UPDATE field_data_field_TEST as ft
left join node as n on ft.entity_id = n.nid
set n.type='test'
where n.type='foo'
I tried using db_update()->join();
but it didn't work.
db_update()
doesn't implement any interfaces that have join()
/innerJoin()
/etc. methods so I think you're stuck with using db_query()
and writing the query string out manually.
$sql = "
UPDATE field_data_field_TEST as ft
left join node as n on ft.entity_id = n.nid
set n.type = :type1
where n.type = :type2";
$args = array(':type1' => 'test', ':type2' => 'foo');
db_query($sql, $args);
db_query()
. If you want to stick rigidly to the documentation then sure, a condition with a subquery would be an option. But as you say, it would be less performant and to me doesn't fell any 'better' than using a straight sql query
Update
doesn't implement any join
functions, still need to use the generic query for this case.
Commented
Jan 10, 2019 at 22:22