Basti
Basti

Reputation: 686

Drupal db_update like condition

Im trying to implement a hook for a DB Update, but I dont get how to implement a "like" condition:

/** 
* Implements Hook_Update_N 
* Menu Database Update - Level 1 - Expanded
*/
function hzd_update_update_7051(&$sandbox) {
  db_update('menu_links')
    ->fields(array(
        'expanded' => 1,
    ))
    ->condition('menu_name', 'main-menu')
    ->condition('plid', '0')
    ->condition('link_path', 'node/%')   <---- This wont work
    ->execute();
};

Upvotes: 1

Views: 850

Answers (1)

Clive
Clive

Reputation: 36955

This'll do it:

function hzd_update_update_7051(&$sandbox) {
  $str = 'node/';

  db_update('menu_links')
    ->fields(array(
      'expanded' => 1,
  ))
  ->condition('menu_name', 'main-menu')
  ->condition('plid', '0')
  ->condition('link_path', db_like($str) . '%', 'LIKE')
  ->execute();
};

Upvotes: 2

Related Questions